[Lock] Log already-locked errors as "notice" instead of "warning"
This commit is contained in:
parent
ae25291610
commit
2a74edb0f9
@ -89,7 +89,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
return true;
|
return true;
|
||||||
} catch (LockConflictedException $e) {
|
} catch (LockConflictedException $e) {
|
||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
$this->logger->warning('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
|
$this->logger->notice('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
|
||||||
|
|
||||||
if ($blocking) {
|
if ($blocking) {
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -97,7 +97,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->warning('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
$this->logger->notice('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
||||||
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
|
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,10 +123,10 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
$this->logger->info('Expiration defined for "{resource}" lock for "{ttl}" seconds.', array('resource' => $this->key, 'ttl' => $this->ttl));
|
$this->logger->info('Expiration defined for "{resource}" lock for "{ttl}" seconds.', array('resource' => $this->key, 'ttl' => $this->ttl));
|
||||||
} catch (LockConflictedException $e) {
|
} catch (LockConflictedException $e) {
|
||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
$this->logger->warning('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
|
$this->logger->notice('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
|
||||||
throw $e;
|
throw $e;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->logger->warning('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
$this->logger->notice('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
|
||||||
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
|
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ final class Lock implements LockInterface, LoggerAwareInterface
|
|||||||
$this->dirty = false;
|
$this->dirty = false;
|
||||||
|
|
||||||
if ($this->store->exists($this->key)) {
|
if ($this->store->exists($this->key)) {
|
||||||
$this->logger->warning('Failed to release the "{resource}" lock.', array('resource' => $this->key));
|
$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 new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Lock\Tests;
|
namespace Symfony\Component\Lock\Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Lock\Exception\LockConflictedException;
|
use Symfony\Component\Lock\Exception\LockConflictedException;
|
||||||
use Symfony\Component\Lock\Key;
|
use Symfony\Component\Lock\Key;
|
||||||
use Symfony\Component\Lock\Lock;
|
use Symfony\Component\Lock\Lock;
|
||||||
@ -192,6 +193,35 @@ class LockTest extends TestCase
|
|||||||
$lock->release();
|
$lock->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
|
||||||
|
*/
|
||||||
|
public function testReleaseThrowsAndLog()
|
||||||
|
{
|
||||||
|
$key = new Key(uniqid(__METHOD__, true));
|
||||||
|
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
|
||||||
|
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||||
|
$lock = new Lock($key, $store, 10, true);
|
||||||
|
$lock->setLogger($logger);
|
||||||
|
|
||||||
|
$logger->expects($this->atLeastOnce())
|
||||||
|
->method('notice')
|
||||||
|
->with('Failed to release the "{resource}" lock.', array('resource' => $key));
|
||||||
|
|
||||||
|
$store
|
||||||
|
->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with($key);
|
||||||
|
|
||||||
|
$store
|
||||||
|
->expects($this->once())
|
||||||
|
->method('exists')
|
||||||
|
->with($key)
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
|
$lock->release();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideExpiredDates
|
* @dataProvider provideExpiredDates
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user