Wrap release exception
This commit is contained in:
parent
1fc66ff080
commit
c37f9e9e32
@ -147,12 +147,22 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
||||
*/
|
||||
public function release()
|
||||
{
|
||||
$this->store->delete($this->key);
|
||||
$this->dirty = false;
|
||||
try {
|
||||
try {
|
||||
$this->store->delete($this->key);
|
||||
$this->dirty = false;
|
||||
} catch (LockReleasingException $e) {
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key), 0, $e);
|
||||
}
|
||||
|
||||
if ($this->store->exists($this->key)) {
|
||||
if ($this->store->exists($this->key)) {
|
||||
throw new LockReleasingException(sprintf('Failed to release the "%s" lock, the resource is still locked.', $this->key));
|
||||
}
|
||||
} catch (LockReleasingException $e) {
|
||||
$this->logger->notice('Failed to release the "{resource}" lock.', array('resource' => $this->key));
|
||||
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,6 +184,29 @@ class LockTest extends TestCase
|
||||
unset($lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
|
||||
*/
|
||||
public function testReleaseThrowsExceptionWhenDeletionFail()
|
||||
{
|
||||
$key = new Key(uniqid(__METHOD__, true));
|
||||
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
|
||||
$lock = new Lock($key, $store, 10);
|
||||
|
||||
$store
|
||||
->expects($this->once())
|
||||
->method('delete')
|
||||
->with($key)
|
||||
->willThrowException(new \RuntimeException('Boom'));
|
||||
|
||||
$store
|
||||
->expects($this->never())
|
||||
->method('exists')
|
||||
->with($key);
|
||||
|
||||
$lock->release();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user