You are here

public function ServiceTest::testHandleResults in Purge 8.3

Tests \Drupal\purge\Plugin\Purge\Queue\QueueService::handleResults.

File

tests/src/Kernel/Queue/ServiceTest.php, line 204

Class

ServiceTest
Tests \Drupal\purge\Plugin\Purge\Queue\QueueService.

Namespace

Drupal\Tests\purge\Kernel\Queue

Code

public function testHandleResults() : void {
  $this->service
    ->add($this->queuer, $this
    ->getInvalidations(5));

  // Claim for 1s, mark as purged and assert it gets deleted.
  $claims = $this->service
    ->claim(1, 10);
  $claims[0]
    ->setStateContext('purger1');
  $claims[0]
    ->setState(InvalidationInterface::SUCCEEDED);
  $this->service
    ->handleResults($claims);
  sleep(3);

  // Claim for 2s, mark all as not-successfull and assert releases.
  $claims = $this->service
    ->claim(10, 2);
  $this
    ->assertTrue(4 === count($claims));
  foreach ($claims as $claim) {
    $claim
      ->setStateContext('purger1');
  }
  $claims[0]
    ->setState(InvalidationInterface::SUCCEEDED);
  $claims[1]
    ->setState(InvalidationInterface::PROCESSING);
  $claims[2]
    ->setState(InvalidationInterface::FAILED);
  $claims[3]
    ->setState(InvalidationInterface::NOT_SUPPORTED);
  $this->service
    ->handleResults($claims);
  sleep(4);
  $this
    ->assertTrue(3 === count($this->service
    ->claim(10, 10)));
}