Skip to content

Commit

Permalink
Let's try this
Browse files Browse the repository at this point in the history
  • Loading branch information
arvenil committed Jun 12, 2015
1 parent 030f32b commit 3f0b3c5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/NinjaMutex/Lock/MemcacheLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/NinjaMutex/Lock/MemcachedLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 1 addition & 13 deletions tests/NinjaMutex/Lock/LockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}

0 comments on commit 3f0b3c5

Please sign in to comment.