From 27892e5d1098cf370d6b679d84fd800d105920ab Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 8 May 2026 17:16:58 +0200 Subject: [PATCH] Fix eviction-guard test premise after dropping the (pid, server) unique index testAddDoesNotEvictRecentRowOnSamePidServer was asserting QueryException, which fired before #494 because the unique (pid, server) index rejected the second insert. With the unique constraint dropped, the second insert succeeds, so the test premise no longer holds and master CI failed. Reframe the test to verify what it actually cares about: the eviction guard (`modified <` threshold) inside add() must NOT remove a fresh row. After the second add() on the same (pid, server), assert the pre-existing fresh row still exists. Coverage of the threshold check is preserved; the duplicate-allowed behavior is already covered by testAddAllowsDuplicatePidServer. --- .../Model/Table/QueueProcessesTableTest.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/TestCase/Model/Table/QueueProcessesTableTest.php b/tests/TestCase/Model/Table/QueueProcessesTableTest.php index bd6d0031..4fab7ae0 100644 --- a/tests/TestCase/Model/Table/QueueProcessesTableTest.php +++ b/tests/TestCase/Model/Table/QueueProcessesTableTest.php @@ -4,7 +4,6 @@ namespace Queue\Test\TestCase\Model\Table; use Cake\Core\Configure; -use Cake\Database\Exception\QueryException; use Cake\I18n\DateTime; use Cake\ORM\Exception\PersistenceFailedException; use Cake\ORM\TableRegistry; @@ -311,20 +310,23 @@ public function testAddEvictsStaleRowOnSamePidServer() { /** * If the existing row is fresh (recent heartbeat), it represents a real, - * live worker — eviction would be wrong. The duplicate-key error is the - * correct outcome. `Queue.maxworkers` is raised so `validateCount` cannot - * mask the real source of failure: the (pid, server) unique index fires - * at the DB level as a `QueryException`, not validation. + * live worker — the eviction guard inside `add()` must NOT touch it. + * Verifies the threshold check (`modified <` clause) by asserting the + * pre-existing row survives a second `add()` on the same (pid, server). * * @return void */ public function testAddDoesNotEvictRecentRowOnSamePidServer() { Configure::write('Queue.maxworkers', 5); $this->QueueProcesses->deleteAll(['1=1']); - $this->QueueProcesses->add('8', 'first-workerkey'); + $firstId = $this->QueueProcesses->add('8', 'first-workerkey'); - $this->expectException(QueryException::class); $this->QueueProcesses->add('8', 'second-workerkey'); + + $this->assertTrue( + $this->QueueProcesses->exists(['id' => $firstId]), + 'Recent row should not be evicted by a subsequent add() on the same (pid, server).', + ); } /**