public function SubmissionsCompletedSinceLastSuccessTest::testSubmissionCreationTimeScheduleRaceConditions in Webform Scheduled Tasks 8.2
@covers ::getResultSet
File
- tests/
src/ Kernel/ SubmissionsCompletedSinceLastSuccessTest.php, line 124
Class
- SubmissionsCompletedSinceLastSuccessTest
- Submissions since last success result set plugin test.
Namespace
Drupal\Tests\webform_scheduled_tasks\KernelCode
public function testSubmissionCreationTimeScheduleRaceConditions() {
// @codingStandardsIgnoreStart
// In the following timeline, the plugin should select submission b to c,
// but exclude d, since it was created on or after the thread started
// running. The next run will capture d and e, since the recorded time for a
// successful run is the request time:
// (sub a) (last completed) (sub c) (request time) (sub e) (execute)
// (sub b) (sub d)
// The "last completed" in the diagram will be primed to the current time.
// @codingStandardsIgnoreEnd
$this
->assertSubmissionResults([]);
$this->schedule
->registerSuccessfulTask();
// Submission B will be created at exactly the same time that the last task
// ran.
$submission_b = $this
->createTestSubmission([]);
$this
->timePasses();
$submission_c = $this
->createTestSubmission([]);
$this
->timePasses();
// Submission D happens at the exact time the plugin is executing for a
// second time.
$submission_d = $this
->createTestSubmission([]);
// Submission E happens between the request time and the time the plugin
// takes to execute. Simulate this by pitching submission e, 1 second into
// the future.
$submission_e = $this
->createTestSubmission([
'completed' => $this->currentTime + 1,
]);
$this
->assertSubmissionResults([
$submission_b,
$submission_c,
]);
$this->schedule
->registerSuccessfulTask();
// Elapse two seconds, one of the simulated second of execution that
// submission e used and one second between running intervals of the next
// scheduled job.
$this
->timePasses();
$this
->timePasses();
$this
->assertSubmissionResults([
$submission_d,
$submission_e,
]);
}