diff --git a/src/Symfony/Component/Lock/Lock.php b/src/Symfony/Component/Lock/Lock.php index 078813801681e..ccb0184c18926 100644 --- a/src/Symfony/Component/Lock/Lock.php +++ b/src/Symfony/Component/Lock/Lock.php @@ -121,6 +121,7 @@ public function acquire(bool $blocking = false): bool */ public function acquireRead(bool $blocking = false): bool { + $this->key->resetLifetime(); try { if (!$this->store instanceof SharedLockStoreInterface) { $this->logger->debug('Store does not support ReadLocks, fallback to WriteLock.', ['resource' => $this->key]); diff --git a/src/Symfony/Component/Lock/Tests/LockTest.php b/src/Symfony/Component/Lock/Tests/LockTest.php index cc8b96f561ed2..fb83293637cac 100644 --- a/src/Symfony/Component/Lock/Tests/LockTest.php +++ b/src/Symfony/Component/Lock/Tests/LockTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Lock\Lock; use Symfony\Component\Lock\PersistingStoreInterface; use Symfony\Component\Lock\SharedLockStoreInterface; +use Symfony\Component\Lock\Store\ExpiringStoreTrait; /** * @author Jérémy Derussé @@ -429,6 +430,52 @@ public function testAcquireReadNoBlockingWithSharedLockStoreInterface() $this->assertTrue($lock->acquireRead(false)); } + /** + * @group time-sensitive + */ + public function testAcquireReadTwiceWithExpiration() + { + $key = new Key(uniqid(__METHOD__, true)); + $store = new class() implements PersistingStoreInterface { + use ExpiringStoreTrait; + private $keys = []; + private $initialTtl = 30; + + public function save(Key $key) + { + $key->reduceLifetime($this->initialTtl); + $this->keys[spl_object_hash($key)] = $key; + $this->checkNotExpired($key); + + return true; + } + + public function delete(Key $key) + { + unset($this->keys[spl_object_hash($key)]); + } + + public function exists(Key $key) + { + return isset($this->keys[spl_object_hash($key)]); + } + + public function putOffExpiration(Key $key, float $ttl) + { + $key->reduceLifetime($ttl); + $this->checkNotExpired($key); + } + }; + $ttl = 1; + $lock = new Lock($key, $store, $ttl); + + $this->assertTrue($lock->acquireRead()); + $lock->release(); + sleep($ttl + 1); + $this->assertTrue($lock->acquireRead()); + $lock->release(); + } + public function testAcquireReadBlockingWithBlockingSharedLockStoreInterface() { $key = new Key(uniqid(__METHOD__, true)); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy