diff --git a/core/lib/Drupal/Core/Queue/Memory.php b/core/lib/Drupal/Core/Queue/Memory.php index 2e4ac0f..67bf078 100644 --- a/core/lib/Drupal/Core/Queue/Memory.php +++ b/core/lib/Drupal/Core/Queue/Memory.php @@ -62,7 +62,7 @@ public function numberOfItems() { */ public function claimItem($lease_time = 30) { foreach ($this->queue as $key => $item) { - if ($item->expire == 0) { + if ($item->expire == 0 || time() > $item->expire) { $item->expire = time() + $lease_time; $this->queue[$key] = $item; return $item; diff --git a/core/tests/Drupal/KernelTests/Core/Queue/QueueTest.php b/core/tests/Drupal/KernelTests/Core/Queue/QueueTest.php index cc882ed..7178fb5 100644 --- a/core/tests/Drupal/KernelTests/Core/Queue/QueueTest.php +++ b/core/tests/Drupal/KernelTests/Core/Queue/QueueTest.php @@ -105,12 +105,9 @@ protected function runQueueTest($queue1, $queue2) { $queue1->createItem($data[0]); // First claim the item with a negative lease time so that the item is // marked with a past expire date. - $item = $queue1->claimItem(-10); - // Assert that the expire date was actually set to a past date. - $item_expire = Database::getConnection()->query('SELECT expire FROM {' . DatabaseQueue::TABLE_NAME . '} WHERE item_id = :item_id', [':item_id' => $item->item_id]) - ->fetchField(); - $this->assertTrue($item_expire < time(), 'Queue item expire was\'nt set to a past date.'); - // We should be able to claim the item again since it's expired. + $queue1->claimItem(-3600); + // We should be able to claim the item again, right away, since it's + // expired. $item = $queue1->claimItem(); $this->assertTrue($item, 'Could not claim an expired queue item.'); }