We have the following class:
class MyClass {
public function __construct($lockFactory) {
$this->lockFactory = $lockFactory;
}
public function acquireLock($uuid) {
$lock = $this->lockFactory->createLock($uuid);
return $lock->acquire();
}
public function releaseLock($uuid) {
$lock = $this->lockFactory->createLock($uuid);
$lock->release();
}
}
And the following test
$redis = new Redis();
$redis->connect('redis', 'redis-host');
$lockFactory = new LockFactory(new RedisStore($redis));
$uuid = "6a4eae27-0f75-4df8-bb52-3c902eb2367d";
$myClass = new MyClass()
$acquired1 = $myClass->acquireLock($uuid);
// This lock gets acquired as expected
$this->assertTrue($acquired1);
$acquired2 = $myClass->acquireLock($uuid);
// This lock fails to get acquired because we already acquired it, as expected
$this->assertFalse($acquired2);
$myClass->releaseLock($uuid);
$acquired3 = $myClass->acquireLock($uuid);
// We would expect this to get acquired because we released it above, but the below assertion fails
$this->assertTrue($acquired3);
Why does it appear that releasing the lock isn't working? From our understanding of the symfony locking component, release should delete the resource in Redis, allowing the lock to be acquired again