Skip to content

Commit 41db1a2

Browse files
committed
Add tests for MongoLock lottery pruning behavior
1 parent 00078fc commit 41db1a2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/Cache/MongoLockTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ public function testInvalidLottery(array $lottery)
3939
);
4040
}
4141

42+
public function testLotteryPrunesExpiredLocks(): void
43+
{
44+
$collection = $this->createMock(Collection::class);
45+
$collection->expects($this->once())
46+
->method('findOneAndUpdate')
47+
->willReturn(['owner' => 'test-owner']);
48+
$collection->expects($this->once())
49+
->method('deleteMany');
50+
51+
$lock = new MongoLock($collection, 'foo', 10, 'test-owner', lottery: [1, 1]);
52+
$lock->acquire();
53+
}
54+
55+
public function testDisabledLotteryDoesNotPruneExpiredLocks(): void
56+
{
57+
$collection = $this->createMock(Collection::class);
58+
$collection->expects($this->once())
59+
->method('findOneAndUpdate')
60+
->willReturn(['owner' => 'test-owner']);
61+
$collection->expects($this->never())
62+
->method('deleteMany');
63+
64+
$lock = new MongoLock($collection, 'foo', 10, 'test-owner', lottery: [0, 0]);
65+
$lock->acquire();
66+
}
67+
4268
public function testLockCanBeAcquired()
4369
{
4470
$lock = $this->getCache()->lock('foo');

0 commit comments

Comments
 (0)