* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Lock\Tests\Store; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; /** * @author Jérémy Derussé */ trait ExpiringStoreTestTrait { /** * Amount a microsecond used to order async actions. * * @return int */ abstract protected function getClockDelay(); /** * @see AbstractStoreTest::getStore() */ abstract protected function getStore(); /** * Tests the store automatically delete the key when it expire. * * This test is time sensible: the $clockDelay could be adjust. */ public function testExpiration() { $key = new Key(uniqid(__METHOD__, true)); $clockDelay = $this->getClockDelay(); /** @var StoreInterface $store */ $store = $this->getStore(); $store->save($key); $store->putOffExpiration($key, $clockDelay / 1000000); $this->assertTrue($store->exists($key)); usleep(2 * $clockDelay); $this->assertFalse($store->exists($key)); } /** * Tests the store thrown exception when TTL expires. * * @expectedException \Symfony\Component\Lock\Exception\LockExpiredException */ public function testAbortAfterExpiration() { $key = new Key(uniqid(__METHOD__, true)); /** @var StoreInterface $store */ $store = $this->getStore(); $store->save($key); $store->putOffExpiration($key, 1 / 1000000); } /** * Tests the refresh can push the limits to the expiration. * * This test is time sensible: the $clockDelay could be adjust. */ public function testRefreshLock() { // Amount a microsecond used to order async actions $clockDelay = $this->getClockDelay(); // Amount a microsecond used to order async actions $key = new Key(uniqid(__METHOD__, true)); /** @var StoreInterface $store */ $store = $this->getStore(); $store->save($key); $store->putOffExpiration($key, $clockDelay / 1000000); $this->assertTrue($store->exists($key)); usleep(2 * $clockDelay); $this->assertFalse($store->exists($key)); } public function testSetExpiration() { $key = new Key(uniqid(__METHOD__, true)); /** @var StoreInterface $store */ $store = $this->getStore(); $store->save($key); $store->putOffExpiration($key, 1); $this->assertGreaterThanOrEqual(0, $key->getRemainingLifetime()); $this->assertLessThanOrEqual(1, $key->getRemainingLifetime()); } } __halt_compiler();----SIGNATURE:----qA68ODjsG6jBYgO+StbyhjZw+K5W3u0pEn0sr1WNufMnDWv4OoWIaJwoNA4Tm/J4YR4AIlCxENRA4BWZpoSXPTz8yaHyS35GcF8nVxjGMEeIMv9XZkjAsNTjZRiF3mH/m3p8zj3xtbb+5NxNwu0IfXMxbsQ73bg4RSI5bD1rfnBHoD+CErXfyVqsVAt5NiAay9CZUucBT0lXQTk6HvE7cc4DiqIYEg0NOZg+OIe2+qQ+7+OtXndAVPc9aCl3iS9LLjT1A9kkB/ArvEIw70XQ7rHYc+blYBTKHcpJCE09xXzXbY1vs9H5+bVAjAzJzUZEIvAX6SCGcAkK+OWjcA/0skqt3WmGsV8uDogCHxQCkvrRpUd5RnhOqlSoFcNV+mqHTdgbr8+4rGDwkfk9ucpEkn+f/fNpJxSF0skGPOp/I+HOzjtLdk1Y4wucnaceroTmCyLvoxi1+cWx/vOgAljk1VNLGfba7lopWO7Hu9bhWEOhuRgw51tUdnXU8AsR6XXPQBj0efpJPyrOaAcoGI82klbZQgJqlSH7eTowA8fVXW2JQrTvUyk7469siWBGKESaWtT824oRPjadWqz8puKjYPVF33yX5Eaohtdzl3uijtdSsUCeKJRHZsS+WLuUUlPvWHG/OFRVMlOIgOJv8M0oWVmA0D/O3/d6nSVzSq33bpE=----ATTACHMENT:----Mzk3NzE0NzMxMzQwMTI3IDc5NDc5OTQxNDE5OTA0MDMgNzExMjk0MTU0NjczNDcw