function CronSuspendQueueDelayTest::testSuspendQueueThreshold
Same name in other branches
- 10 core/tests/Drupal/Tests/Core/Cron/CronSuspendQueueDelayTest.php \Drupal\Tests\Core\Cron\CronSuspendQueueDelayTest::testSuspendQueueThreshold()
Tests queues may be re-processed by whether delay exceeds threshold.
Cron will pause and reprocess a queue after a delay if a worker throws a SuspendQueueException with a delay time not exceeding the maximum wait config.
@dataProvider providerSuspendQueueThreshold
Parameters
float $threshold: The configured threshold.
float $suspendQueueDelay: An interval in seconds a worker will suspend the queue.
bool $expectQueueDelay: Whether to expect cron to sleep and re-process the queue.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cron/ CronSuspendQueueDelayTest.php, line 228
Class
- CronSuspendQueueDelayTest
- Test Cron handling of suspended queues with a delay.
Namespace
Drupal\Tests\Core\CronCode
public function testSuspendQueueThreshold(float $threshold, float $suspendQueueDelay, bool $expectQueueDelay) : void {
$this->cronConstructorArguments['queue_config'] = [
'suspendMaximumWait' => $threshold,
];
[
'queueFactory' => $queueFactory,
'queueManager' => $queueManager,
] = $this->cronConstructorArguments;
$cron = $this->getMockBuilder(Cron::class)
->onlyMethods([
'usleep',
])
->setConstructorArgs($this->cronConstructorArguments)
->getMock();
$cron->expects($expectQueueDelay ? $this->once() : $this->never())
->method('usleep');
$queueManager->expects($this->once())
->method('getDefinitions')
->willReturn([
'test_worker' => [
'id' => 'test_worker',
'cron' => 300,
],
]);
$queue = $this->createMock(QueueInterface::class);
$queueFactory->expects($this->once())
->method('get')
->willReturnMap([
[
'test_worker',
FALSE,
$queue,
],
]);
$queue->expects($this->exactly($expectQueueDelay ? 2 : 1))
->method('claimItem')
->willReturnOnConsecutiveCalls((object) [
'data' => 'test_data',
], FALSE);
$queueManager->expects($this->exactly(1))
->method('createInstance')
->with('test_worker')
->willReturn($this->workerA);
$this->workerA
->expects($this->once())
->method('processItem')
->with($this->anything())
->willReturnOnConsecutiveCalls($this->throwException(new SuspendQueueException('', 0, NULL, $suspendQueueDelay)));
$cron->run();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.