* * 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:----T4NLL5kWk9PwKTKlGLLqGwVAdrNqxnTdYeR5QqqpueL8qvarnq7kA7X0W5PUuhiZz118uCznRMxY+mRwA7ZI/ZX6PdPdGE19cPO406vv/LYq6wN88sHeQrYg/JUGZ+z9APlxk/ggLmO+ywco51tG6yMYpg7JtZl68swtjrszQJ5cWMv9cRrNIjPrDVGYl68jTfK0rQL2+GP+uax9ZeXdRU7xTtVMo+MzlkibdLYXnKtDAc0yFqM+ZN4fFXPEBDFM0V7HQlJ3yGN0+HKlkFR9gspxpWoZUnkmL8ZBZQEEYX4v1XGa6GYrsD5cRV7UqlKYWyEnGxTuwue9+oSy8JCvDDMd+rXAt53+HaTTGljRXfMKcXw255I4EHcvFB9NW05eDm/Y+0qrgIWYW1ZR1nufDca9WiGZ8NXV8hkP2kZQs7otTZNZW/htBsifJnoynm8RN6jIBqFDbtHeDAAconodOxdfys0dPbamItUr2cOGl+PWFDjq0F3ax4Ex1OE2CnOaTUh2iZc8tfxQKsQ1jUGbu00/3zr4Q+fnXGmjie9HJiClDD5t5N8GnSdIUreaFVzYA6J900EJpir4ie6eMCQb8uDXL8miPSxSckDiwE9mJ1QHLigPT+wfAG8SOKw84SVKGCtcRnK74Xbd4gP6n6VQOGGbh2YgScxynfb3cYLF8JY=----ATTACHMENT:----Njg2NTAyNDQ1NzgwMzk4OCAzODU0NDk5MDMxMzA0MTM0IDg4NDU5MzM0NzA4OTI0NjE=