mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-20 11:48:27 -06:00
Ensured Redis lock store is wrapped into a retry adapter
This commit is contained in:
parent
04389fc8b0
commit
73fd348490
@ -2,6 +2,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use Shlinkio\Shlink\Common\Cache\RedisFactory;
|
||||
use Shlinkio\Shlink\Common\Lock\RetryLockStoreDelegatorFactory;
|
||||
use Symfony\Component\Lock;
|
||||
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
|
||||
|
||||
@ -22,6 +23,11 @@ return [
|
||||
'lock_store' => Lock\Store\FlockStore::class,
|
||||
'redis_lock_store' => Lock\Store\RedisStore::class,
|
||||
],
|
||||
'delegators' => [
|
||||
Lock\Store\RedisStore::class => [
|
||||
RetryLockStoreDelegatorFactory::class,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
ConfigAbstractFactory::class => [
|
||||
|
18
module/Common/src/Lock/RetryLockStoreDelegatorFactory.php
Normal file
18
module/Common/src/Lock/RetryLockStoreDelegatorFactory.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Lock;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Symfony\Component\Lock\Store\RetryTillSaveStore;
|
||||
use Symfony\Component\Lock\StoreInterface;
|
||||
|
||||
class RetryLockStoreDelegatorFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container, $name, callable $callback): RetryTillSaveStore
|
||||
{
|
||||
/** @var StoreInterface $originalStore */
|
||||
$originalStore = $callback();
|
||||
return new RetryTillSaveStore($originalStore);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Common\Lock;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
use ReflectionObject;
|
||||
use Shlinkio\Shlink\Common\Lock\RetryLockStoreDelegatorFactory;
|
||||
use Symfony\Component\Lock\StoreInterface;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
|
||||
class RetryLockStoreDelegatorFactoryTest extends TestCase
|
||||
{
|
||||
/** @var RetryLockStoreDelegatorFactory */
|
||||
private $delegator;
|
||||
/** @var ObjectProphecy */
|
||||
private $originalStore;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->originalStore = $this->prophesize(StoreInterface::class)->reveal();
|
||||
$this->delegator = new RetryLockStoreDelegatorFactory();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function originalStoreIsWrappedInRetryStore(): void
|
||||
{
|
||||
$callback = function () {
|
||||
return $this->originalStore;
|
||||
};
|
||||
|
||||
$result = ($this->delegator)(new ServiceManager(), '', $callback);
|
||||
|
||||
$ref = new ReflectionObject($result);
|
||||
$prop = $ref->getProperty('decorated');
|
||||
$prop->setAccessible(true);
|
||||
|
||||
$this->assertSame($this->originalStore, $prop->getValue($result));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user