* * 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:----PipNNaR1JxH1OJVMlRE6ief4Apq4RGMZj3I8+JsfLIf2C3OSdSTUhPmBdoTGmvEq1QKc8T6cBl7CY5F3TaNFiVbzeLgeIlHJ0OfUZYVQmNVu5tEp5q/wLTS/CZLKkM3dMvmP5Bm8Lw4lhbiMjDqQVzln66kClsTcAtRPJ7yPPM/8vmqbqvK9Blb78gal6Y/zultaC/PKwGbnGmbuzWPifiBYSxYzh9jzK+0oT0kFipzOfPtB08Z9f1neiWP7J6ZBmpsIFueBAxudYeU35edPJuKheKUPImSKwrvZgohemrmxCfurjr+e7vzlRDyagDVookJkhjifRdIVMxj0GwHk3zAdqzwmEhbl/xLQyFB1bsYDP3nYNptqI3zMXd8F+Ep4f9rGUk2S5eczwaDFucGzUinnxK3g6BdqOHYnsoMOjYv+A+v6ihgtLGzysXgcfhTNsNDTqhGa+EmssIqj0JgGn36Cn7PDSS855v3+BuabiQJR5w0zt0d0EzqiXxdo/eybRIG6x1hSZ+LnVXjh1zIOU6FxDGlbyx7nsdw6TEeiIl+BBPSPqbi7ZcjukqgMc1EXhDIWdCoe2tyFlGWOrhgCgLsvJQ+NseJbAUoKQwsIhbvd+TTOBg8rMp1Zi32QWnwPaHc0p7RRsFCZA9gutej2xtK0cYpWWPxxX0kPYdF385g=----ATTACHMENT:----NTM1NDY5ODU1NTQ4MTYzMSA5Njc5MzM1MjA0MTkxNzg3IDIyMzgwNzI2NjE2NzI1MA==