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()
This commit is contained in:
commit
3e587d7013
@ -174,7 +174,7 @@ trait RedisTrait
|
||||
$connect = $params['persistent'] || $params['persistent_id'] ? 'pconnect' : 'connect';
|
||||
$redis = new $class();
|
||||
|
||||
$initializer = function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
|
||||
$initializer = static function ($redis) use ($connect, $params, $dsn, $auth, $hosts) {
|
||||
try {
|
||||
@$redis->{$connect}($hosts[0]['host'] ?? $hosts[0]['path'], $hosts[0]['port'] ?? null, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval']);
|
||||
|
||||
@ -226,7 +226,7 @@ trait RedisTrait
|
||||
$redis->setOption(\Redis::OPT_TCP_KEEPALIVE, $params['tcp_keepalive']);
|
||||
}
|
||||
} elseif (is_a($class, \RedisCluster::class, true)) {
|
||||
$initializer = function () use ($class, $params, $dsn, $hosts) {
|
||||
$initializer = static function () use ($class, $params, $dsn, $hosts) {
|
||||
foreach ($hosts as $i => $host) {
|
||||
$hosts[$i] = 'tcp' === $host['scheme'] ? $host['host'].':'.$host['port'] : $host['path'];
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
||||
*/
|
||||
public function acquire(bool $blocking = false): bool
|
||||
{
|
||||
$this->key->resetLifetime();
|
||||
try {
|
||||
if ($blocking) {
|
||||
if (!$this->store instanceof BlockingStoreInterface) {
|
||||
|
@ -18,6 +18,7 @@ use Symfony\Component\Lock\Exception\LockConflictedException;
|
||||
use Symfony\Component\Lock\Key;
|
||||
use Symfony\Component\Lock\Lock;
|
||||
use Symfony\Component\Lock\PersistingStoreInterface;
|
||||
use Symfony\Component\Lock\Store\ExpiringStoreTrait;
|
||||
|
||||
/**
|
||||
* @author Jérémy Derussé <jeremy@derusse.com>
|
||||
@ -372,4 +373,50 @@ class LockTest extends TestCase
|
||||
yield [[0.1], false];
|
||||
yield [[-0.1, null], false];
|
||||
}
|
||||
|
||||
/**
|
||||
* @group time-sensitive
|
||||
*/
|
||||
public function testAcquireTwiceWithExpiration()
|
||||
{
|
||||
$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, $ttl)
|
||||
{
|
||||
$key->reduceLifetime($ttl);
|
||||
$this->checkNotExpired($key);
|
||||
}
|
||||
};
|
||||
$ttl = 1;
|
||||
$lock = new Lock($key, $store, $ttl);
|
||||
|
||||
$this->assertTrue($lock->acquire());
|
||||
$lock->release();
|
||||
sleep($ttl + 1);
|
||||
$this->assertTrue($lock->acquire());
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class StopWorkerOnRestartSignalListenerTest extends TestCase
|
||||
{
|
||||
$cachePool = $this->createMock(CacheItemPoolInterface::class);
|
||||
$cacheItem = $this->createMock(CacheItemInterface::class);
|
||||
$cacheItem->expects($this->once())->method('isHIt')->willReturn(true);
|
||||
$cacheItem->expects($this->once())->method('isHit')->willReturn(true);
|
||||
$cacheItem->expects($this->once())->method('get')->willReturn(null === $lastRestartTimeOffset ? null : time() + $lastRestartTimeOffset);
|
||||
$cachePool->expects($this->once())->method('getItem')->willReturn($cacheItem);
|
||||
|
||||
@ -54,7 +54,7 @@ class StopWorkerOnRestartSignalListenerTest extends TestCase
|
||||
{
|
||||
$cachePool = $this->createMock(CacheItemPoolInterface::class);
|
||||
$cacheItem = $this->createMock(CacheItemInterface::class);
|
||||
$cacheItem->expects($this->once())->method('isHIt')->willReturn(false);
|
||||
$cacheItem->expects($this->once())->method('isHit')->willReturn(false);
|
||||
$cacheItem->expects($this->never())->method('get');
|
||||
$cachePool->expects($this->once())->method('getItem')->willReturn($cacheItem);
|
||||
|
||||
|
@ -33,6 +33,9 @@
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,9 @@
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,9 @@
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,9 @@
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-version": "2.1"
|
||||
"branch-version": "2.1",
|
||||
"branch-alias": {
|
||||
"dev-main": "2.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user