You are here

public function DatabaseBackendTest::testFutureQueue in Advanced Queue 8

@covers ::enqueueJob @covers ::claimJob

File

tests/src/Kernel/DatabaseBackendTest.php, line 175

Class

DatabaseBackendTest
@coversDefaultClass \Drupal\advancedqueue\Plugin\AdvancedQueue\Backend\Database @group advancedqueue

Namespace

Drupal\Tests\advancedqueue\Kernel

Code

public function testFutureQueue() {
  $first_job = Job::create('simple', [
    'test' => '1',
  ]);
  $second_job = Job::create('simple', [
    'test' => '2',
  ]);
  $this->firstQueue
    ->getBackend()
    ->enqueueJob($first_job, 5);
  $this->firstQueue
    ->getBackend()
    ->enqueueJob($second_job);
  $this
    ->assertQueuedJob(1, 'first_queue', 5, $first_job);
  $this
    ->assertQueuedJob(2, 'first_queue', 0, $second_job);

  // Update the job to match how it will look when claimed.
  $second_job
    ->setState(Job::STATE_PROCESSING);
  $second_job
    ->setExpiresTime(635814000 + 5);

  // Confirm that the first job isn't available because of the delay.
  $second_claimed_job = $this->firstQueue
    ->getBackend()
    ->claimJob();
  $this
    ->assertEquals($second_job, $second_claimed_job);
  $this
    ->assertNull($this->firstQueue
    ->getBackend()
    ->claimJob());

  // Confirm that rewinding time makes the first job available.
  $this
    ->rewindTime(635814010);
  $first_job
    ->setState(Job::STATE_PROCESSING);
  $first_job
    ->setExpiresTime(635814010 + 5);
  $first_claimed_job = $this->firstQueue
    ->getBackend()
    ->claimJob();
  $this
    ->assertEquals($first_job, $first_claimed_job);
}