diff --git a/src/NinjaMutex/Lock/MemcacheLock.php b/src/NinjaMutex/Lock/MemcacheLock.php index f306c8e..e225d93 100644 --- a/src/NinjaMutex/Lock/MemcacheLock.php +++ b/src/NinjaMutex/Lock/MemcacheLock.php @@ -83,7 +83,7 @@ protected function getLock($name, $blocking) */ public function releaseLock($name) { - if (isset($this->locks[$name]) && $this->memcache->delete($name)) { + if (isset($this->locks[$name]) && ($this->memcache->delete($name) || !$this->isLocked($name))) { unset($this->locks[$name]); return true; diff --git a/src/NinjaMutex/Lock/MemcachedLock.php b/src/NinjaMutex/Lock/MemcachedLock.php index 21c1ca1..61cd465 100644 --- a/src/NinjaMutex/Lock/MemcachedLock.php +++ b/src/NinjaMutex/Lock/MemcachedLock.php @@ -83,7 +83,7 @@ protected function getLock($name, $blocking) */ public function releaseLock($name) { - if (isset($this->locks[$name]) && $this->memcached->delete($name)) { + if (isset($this->locks[$name]) && ($this->memcached->delete($name) || !$this->isLocked($name))) { unset($this->locks[$name]); return true; diff --git a/tests/NinjaMutex/Lock/LockTest.php b/tests/NinjaMutex/Lock/LockTest.php index 6919130..7f78180 100644 --- a/tests/NinjaMutex/Lock/LockTest.php +++ b/tests/NinjaMutex/Lock/LockTest.php @@ -166,7 +166,6 @@ public function testIfLockDestructorThrowsWhenBackendIsUnavailable(LockInterface /** * @issue https://github.com/arvenil/ninja-mutex/issues/12 * @medium Timeout for test increased to ~5s http://stackoverflow.com/a/10535787/916440 - * @runInSeparateProcess * * @dataProvider lockFabricWithExpirationProvider * @param LockFabricWithExpirationInterface $lockFabricWithExpiration @@ -192,17 +191,6 @@ public function testExpiration(LockFabricWithExpirationInterface $lockFabricWith // Cleanup $this->assertTrue($lockImplementor->releaseLock($name, 0)); - - // Now we set null to the Mutex with lock expiration to invoke __destructor - try { - $lockImplementorWithExpiration = null; - } catch (Exception $e) { - // hhvm doesn't throw an exception here, it rather raises a fatal error, - // so I can't check here if Exception was really raised for all builds. - // Looks like I should always raise fatal error in __destructor for all versions rather than trying to raise exception - // https://github.com/facebook/hhvm/blob/af329776c9f740cc1c8c4791f673ba5aa49042ce/hphp/doc/inconsistencies#L40-L48 - // http://docs.hhvm.com/manual/en/language.oop5.decon.php#language.oop5.decon.destructor - // https://github.com/sebastianbergmann/phpunit/issues/1640 - } + $this->assertTrue($lockImplementorWithExpiration->releaseLock($name, 0)); } }