You are here

public function ProcessorTest::testTimeLimit in Advanced Queue 8

@covers ::processQueue

File

tests/src/Kernel/ProcessorTest.php, line 163

Class

ProcessorTest
@coversDefaultClass \Drupal\advancedqueue\Processor @group advancedqueue

Namespace

Drupal\Tests\advancedqueue\Kernel

Code

public function testTimeLimit() {
  $this->queue
    ->setProcessingTime(2);
  $this->queue
    ->save();
  $first_job = Job::create('sleepy', [
    'test' => '1',
  ]);
  $second_job = Job::create('sleepy', [
    'test' => '1',
  ]);
  $third_job = Job::create('sleepy', [
    'test' => '1',
  ]);
  $this->queue
    ->enqueueJob($first_job);
  $this->queue
    ->enqueueJob($second_job);
  $this->queue
    ->enqueueJob($third_job);
  $num_processed = $this->processor
    ->processQueue($this->queue);
  $this
    ->assertEquals(2, $num_processed);
  $counts = $this->queue
    ->getBackend()
    ->countJobs();
  $this
    ->assertEquals([
    Job::STATE_QUEUED => 1,
    Job::STATE_SUCCESS => 2,
  ], array_filter($counts));
  $num_processed = $this->processor
    ->processQueue($this->queue);
  $this
    ->assertEquals(1, $num_processed);
  $counts = $this->queue
    ->getBackend()
    ->countJobs();
  $this
    ->assertEquals([
    Job::STATE_SUCCESS => 3,
  ], array_filter($counts));
}