/** * @issue https://github.com/arvenil/ninja-mutex/issues/12 * @medium Timeout for test increased to ~5s http://stackoverflow.com/a/10535787/916440 * * @dataProvider lockFabricWithExpirationProvider * @param LockFabricWithExpirationInterface $lockFabricWithExpiration */ public function testExpiration(LockFabricWithExpirationInterface $lockFabricWithExpiration) { $expiration = 2; // in seconds $name = "lockWithExpiration_" . uniqid(); $lockImplementor = $lockFabricWithExpiration->create(); $lockImplementorWithExpiration = $lockFabricWithExpiration->create(); $lockImplementorWithExpiration->setExpiration($expiration); // Aquire lock on implementor with lock expiration $this->assertTrue($lockImplementorWithExpiration->acquireLock($name, 0)); // We hope code was fast enough so $expiration time didn't pass yet and lock still should be held $this->assertFalse($lockImplementor->acquireLock($name, 0)); // Let's wait for lock to expire sleep($expiration); // Let's try again to lock $this->assertTrue($lockImplementor->acquireLock($name, 0)); // Cleanup $this->assertTrue($lockImplementor->releaseLock($name, 0)); // Expired lock is unusable, we need to clean it's lock state or otherwise // it will invoke in __destruct Exception (php*) or Fatal Error (hhvm) $this->assertTrue($lockImplementorWithExpiration->clearLock($name, 0)); }