function CronQueueTest::testSuspendQueueException
Same name in other branches
- 11.x core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::testSuspendQueueException()
Tests suspend queue exception is handled properly.
@covers \Drupal\Core\Queue\SuspendQueueException
See also
\Drupal\cron_queue_test\Plugin\QueueWorker\CronQueueTestSuspendQueue
File
-
core/
modules/ system/ tests/ src/ Kernel/ System/ CronQueueTest.php, line 226
Class
- CronQueueTest
- Tests the Cron Queue runner.
Namespace
Drupal\Tests\system\Kernel\SystemCode
public function testSuspendQueueException() : void {
$this->logger
->log(RfcLogLevel::DEBUG, 'A worker for @queue queue suspended further processing of the queue.', Argument::that(function ($args) {
return $args['@queue'] === CronQueueTestSuspendQueue::PLUGIN_ID;
}))
->shouldBeCalled();
$this->logger
->log(RfcLogLevel::INFO, 'Cron run completed.', Argument::cetera())
->shouldBeCalled();
// Get the queue to test the specific SuspendQueueException.
$queue = \Drupal::queue(CronQueueTestSuspendQueue::PLUGIN_ID);
// Enqueue several item for processing.
$queue->createItem('process');
$queue->createItem('suspend');
$queue->createItem('ignored');
// Run cron; the worker for this queue should process as far as the
// suspending item.
$this->cron
->run();
// Only one item should have been processed.
$this->assertEquals(2, $queue->numberOfItems(), 'Suspended queue stopped processing at the suspending item.');
// Check the items remaining in the queue. The item that throws the
// exception gets released by cron, so we can claim it again to check it.
$item = $queue->claimItem();
$this->assertEquals('suspend', $item->data, 'Suspending item remains in the queue.');
$item = $queue->claimItem();
$this->assertEquals('ignored', $item->data, 'Item beyond the suspending item remains in the queue.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.