Skip to content

Commit 3e587d7

Browse files
Merge branch '4.4' into 5.1
* 4.4: [Contracts] add branch-aliases for dev-main [Cache] Make Redis initializers static Fix tests typo [Lock] Reset Key lifetime time before we acquire it [CI] Silence errors when remove file/dir on test tearDown()
2 parents 4529e08 + 6ba6ae7 commit 3e587d7

File tree

11 files changed

+80
-11
lines changed

11 files changed

+80
-11
lines changed

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public static function createConnection($dsn, array $options = [])
174174
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
175175
$redis = new $class();
176176

177-
$initializer = function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
177+
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
178178
try {
179179
@$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
180180

@@ -226,7 +226,7 @@ public static function createConnection($dsn, array $options = [])
226226
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
227227
}
228228
} elseif (is_a($class, \RedisCluster::class, true)) {
229-
$initializer = function () use ($class, $params, $dsn, $hosts) {
229+
$initializer = static function () use ($class, $params, $dsn, $hosts) {
230230
foreach ($hosts as $i => $host) {
231231
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
232232
}

src/Symfony/Component/Lock/Lock.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function __destruct()
6767
*/
6868
public function acquire(bool $blocking = false): bool
6969
{
70+
$this->key->resetLifetime();
7071
try {
7172
if ($blocking) {
7273
if (!$this->store instanceof BlockingStoreInterface) {

src/Symfony/Component/Lock/Tests/LockTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Lock\Key;
1919
use Symfony\Component\Lock\Lock;
2020
use Symfony\Component\Lock\PersistingStoreInterface;
21+
use Symfony\Component\Lock\Store\ExpiringStoreTrait;
2122

2223
/**
2324
* @author Jérémy Derussé <[email protected]>
@@ -372,4 +373,50 @@ public function provideExpiredDates()
372373
yield [[0.1], false];
373374
yield [[-0.1, null], false];
374375
}
376+
377+
/**
378+
* @group time-sensitive
379+
*/
380+
public function testAcquireTwiceWithExpiration()
381+
{
382+
$key = new Key(uniqid(__METHOD__, true));
383+
$store = new class() implements PersistingStoreInterface {
384+
use ExpiringStoreTrait;
385+
private $keys = [];
386+
private $initialTtl = 30;
387+
388+
public function save(Key $key)
389+
{
390+
$key->reduceLifetime($this->initialTtl);
391+
$this->keys[spl_object_hash($key)] = $key;
392+
$this->checkNotExpired($key);
393+
394+
return true;
395+
}
396+
397+
public function delete(Key $key)
398+
{
399+
unset($this->keys[spl_object_hash($key)]);
400+
}
401+
402+
public function exists(Key $key)
403+
{
404+
return isset($this->keys[spl_object_hash($key)]);
405+
}
406+
407+
public function putOffExpiration(Key $key, $ttl)
408+
{
409+
$key->reduceLifetime($ttl);
410+
$this->checkNotExpired($key);
411+
}
412+
};
413+
$ttl = 1;
414+
$lock = new Lock($key, $store, $ttl);
415+
416+
$this->assertTrue($lock->acquire());
417+
$lock->release();
418+
sleep($ttl + 1);
419+
$this->assertTrue($lock->acquire());
420+
$lock->release();
421+
}
375422
}

src/Symfony/Component/Messenger/Tests/EventListener/StopWorkerOnRestartSignalListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testWorkerStopsWhenMemoryLimitExceeded(?int $lastRestartTimeOffs
3030
{
3131
$cachePool = $this->createMock(CacheItemPoolInterface::class);
3232
$cacheItem = $this->createMock(CacheItemInterface::class);
33-
$cacheItem->expects($this->once())->method('isHIt')->willReturn(true);
33+
$cacheItem->expects($this->once())->method('isHit')->willReturn(true);
3434
$cacheItem->expects($this->once())->method('get')->willReturn(null === $lastRestartTimeOffset ? null : time() + $lastRestartTimeOffset);
3535
$cachePool->expects($this->once())->method('getItem')->willReturn($cacheItem);
3636

@@ -54,7 +54,7 @@ public function testWorkerDoesNotStopIfRestartNotInCache()
5454
{
5555
$cachePool = $this->createMock(CacheItemPoolInterface::class);
5656
$cacheItem = $this->createMock(CacheItemInterface::class);
57-
$cacheItem->expects($this->once())->method('isHIt')->willReturn(false);
57+
$cacheItem->expects($this->once())->method('isHit')->willReturn(false);
5858
$cacheItem->expects($this->never())->method('get');
5959
$cachePool->expects($this->once())->method('getItem')->willReturn($cacheItem);
6060

src/Symfony/Contracts/Cache/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
}
3434
},
3535
"extra": {
36-
"branch-version": "2.1"
36+
"branch-version": "2.1",
37+
"branch-alias": {
38+
"dev-main": "2.1-dev"
39+
}
3740
}
3841
}

src/Symfony/Contracts/Deprecation/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
},
2525
"minimum-stability": "dev",
2626
"extra": {
27-
"branch-version": "2.1"
27+
"branch-version": "2.1",
28+
"branch-alias": {
29+
"dev-main": "2.1-dev"
30+
}
2831
}
2932
}

src/Symfony/Contracts/EventDispatcher/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
}
3434
},
3535
"extra": {
36-
"branch-version": "2.1"
36+
"branch-version": "2.1",
37+
"branch-alias": {
38+
"dev-main": "2.1-dev"
39+
}
3740
}
3841
}

src/Symfony/Contracts/HttpClient/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
}
3333
},
3434
"extra": {
35-
"branch-version": "2.1"
35+
"branch-version": "2.1",
36+
"branch-alias": {
37+
"dev-main": "2.1-dev"
38+
}
3639
}
3740
}

src/Symfony/Contracts/Service/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
}
3434
},
3535
"extra": {
36-
"branch-version": "2.1"
36+
"branch-version": "2.1",
37+
"branch-alias": {
38+
"dev-main": "2.1-dev"
39+
}
3740
}
3841
}

src/Symfony/Contracts/Translation/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
}
3333
},
3434
"extra": {
35-
"branch-version": "2.1"
35+
"branch-version": "2.1",
36+
"branch-alias": {
37+
"dev-main": "2.1-dev"
38+
}
3639
}
3740
}

0 commit comments

Comments
 (0)