mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix tests on ChillDocumentLockManager: take expiration delay into account
This commit is contained in:
parent
c33330969c
commit
398bbd12d5
@ -26,8 +26,10 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface
|
|||||||
*/
|
*/
|
||||||
private const LOCK_GRACEFUL_DURATION_TIME = 3;
|
private const LOCK_GRACEFUL_DURATION_TIME = 3;
|
||||||
|
|
||||||
public function __construct(private readonly ChillRedis $redis)
|
public function __construct(
|
||||||
{
|
private readonly ChillRedis $redis,
|
||||||
|
private int $ttlAfterDeleteSeconds = self::LOCK_GRACEFUL_DURATION_TIME
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteLock(Document $document, RequestInterface $request): bool
|
public function deleteLock(Document $document, RequestInterface $request): bool
|
||||||
@ -38,7 +40,7 @@ class ChillDocumentLockManager implements DocumentLockManagerInterface
|
|||||||
|
|
||||||
// some queries (ex.: putFile) may be executed on the same time than the unlock, so
|
// some queries (ex.: putFile) may be executed on the same time than the unlock, so
|
||||||
// we add a delay before unlocking the file, instead of deleting it immediatly
|
// we add a delay before unlocking the file, instead of deleting it immediatly
|
||||||
return $this->redis->expire($this->getCacheId($document), self::LOCK_GRACEFUL_DURATION_TIME);
|
return $this->redis->expire($this->getCacheId($document), $this->ttlAfterDeleteSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLock(Document $document, RequestInterface $request): string
|
public function getLock(Document $document, RequestInterface $request): string
|
||||||
|
@ -31,27 +31,6 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
|||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleLoops()
|
|
||||||
{
|
|
||||||
$manager = $this->makeManager(1);
|
|
||||||
$document = new StoredObject();
|
|
||||||
$request = $this->prophesize(RequestInterface::class);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
while (50 > ++$i) {
|
|
||||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
|
||||||
|
|
||||||
$this->assertTrue($manager->setLock($document, 'dummy', $request->reveal()));
|
|
||||||
|
|
||||||
$this->assertEquals('dummy', $manager->getLock($document, $request->reveal()));
|
|
||||||
|
|
||||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
|
||||||
|
|
||||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRelock()
|
public function testRelock()
|
||||||
{
|
{
|
||||||
$manager = $this->makeManager(1);
|
$manager = $this->makeManager(1);
|
||||||
@ -70,6 +49,8 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
|||||||
|
|
||||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||||
|
|
||||||
|
sleep(3); // wait for redis to remove the key
|
||||||
|
|
||||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,10 +68,12 @@ final class ChillDocumentLockManagerTest extends KernelTestCase
|
|||||||
|
|
||||||
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
$this->assertTrue($manager->deleteLock($document, $request->reveal()));
|
||||||
|
|
||||||
|
sleep(3); // wait for redis to remove the key
|
||||||
|
|
||||||
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
$this->assertFalse($manager->hasLock($document, $request->reveal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function makeManager(int $ttlAfterDeleteSeconds): ChillDocumentLockManager
|
private function makeManager(int $ttlAfterDeleteSeconds = -1): ChillDocumentLockManager
|
||||||
{
|
{
|
||||||
$redis = self::$container->get(ChillRedis::class);
|
$redis = self::$container->get(ChillRedis::class);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user