File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
src/Symfony/Component/Semaphore Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,11 @@ public function getState(string $stateKey)
80
80
return $ this ->state [$ stateKey ];
81
81
}
82
82
83
+ public function resetLifetime (): void
84
+ {
85
+ $ this ->expiringTime = null ;
86
+ }
87
+
83
88
public function reduceLifetime (float $ ttlInSeconds )
84
89
{
85
90
$ newTime = microtime (true ) + $ ttlInSeconds ;
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ public function __destruct()
66
66
public function acquire (): bool
67
67
{
68
68
try {
69
+ $ this ->key ->resetLifetime ();
69
70
$ this ->store ->save ($ this ->key , $ this ->ttlInSecond );
70
71
$ this ->key ->reduceLifetime ($ this ->ttlInSecond );
71
72
$ this ->dirty = true ;
@@ -97,6 +98,7 @@ public function refresh(?float $ttlInSecond = null)
97
98
}
98
99
99
100
try {
101
+ $ this ->key ->resetLifetime ();
100
102
$ this ->store ->putOffExpiration ($ this ->key , $ ttlInSecond );
101
103
$ this ->key ->reduceLifetime ($ ttlInSecond );
102
104
Original file line number Diff line number Diff line change @@ -252,4 +252,24 @@ public function testExpiration()
252
252
$ semaphore = new Semaphore ($ key , $ store );
253
253
$ this ->assertTrue ($ semaphore ->isExpired ());
254
254
}
255
+
256
+ /**
257
+ * @group time-sensitive
258
+ */
259
+ public function testExpirationResetAfter ()
260
+ {
261
+ $ store = $ this ->getMockBuilder (PersistingStoreInterface::class)->getMock ();
262
+
263
+ $ key = new Key ('key ' , 1 );
264
+ $ semaphore = new Semaphore ($ key , $ store , 1 );
265
+
266
+ $ semaphore ->acquire ();
267
+ $ this ->assertFalse ($ semaphore ->isExpired ());
268
+ $ semaphore ->release ();
269
+
270
+ sleep (2 );
271
+
272
+ $ semaphore ->acquire ();
273
+ $ this ->assertFalse ($ semaphore ->isExpired ());
274
+ }
255
275
}
You can’t perform that action at this time.
0 commit comments