Skip to content

Commit b4122ef

Browse files
authored
Fix eviction-guard test premise after dropping the (pid, server) unique index (#495)
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.
1 parent 0e93a9b commit b4122ef

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

tests/TestCase/Model/Table/QueueProcessesTableTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace Queue\Test\TestCase\Model\Table;
55

66
use Cake\Core\Configure;
7-
use Cake\Database\Exception\QueryException;
87
use Cake\I18n\DateTime;
98
use Cake\ORM\Exception\PersistenceFailedException;
109
use Cake\ORM\TableRegistry;
@@ -311,20 +310,23 @@ public function testAddEvictsStaleRowOnSamePidServer() {
311310

312311
/**
313312
* If the existing row is fresh (recent heartbeat), it represents a real,
314-
* live worker — eviction would be wrong. The duplicate-key error is the
315-
* correct outcome. `Queue.maxworkers` is raised so `validateCount` cannot
316-
* mask the real source of failure: the (pid, server) unique index fires
317-
* at the DB level as a `QueryException`, not validation.
313+
* live worker — the eviction guard inside `add()` must NOT touch it.
314+
* Verifies the threshold check (`modified <` clause) by asserting the
315+
* pre-existing row survives a second `add()` on the same (pid, server).
318316
*
319317
* @return void
320318
*/
321319
public function testAddDoesNotEvictRecentRowOnSamePidServer() {
322320
Configure::write('Queue.maxworkers', 5);
323321
$this->QueueProcesses->deleteAll(['1=1']);
324-
$this->QueueProcesses->add('8', 'first-workerkey');
322+
$firstId = $this->QueueProcesses->add('8', 'first-workerkey');
325323

326-
$this->expectException(QueryException::class);
327324
$this->QueueProcesses->add('8', 'second-workerkey');
325+
326+
$this->assertTrue(
327+
$this->QueueProcesses->exists(['id' => $firstId]),
328+
'Recent row should not be evicted by a subsequent add() on the same (pid, server).',
329+
);
328330
}
329331

330332
/**

0 commit comments

Comments
 (0)