Skip to content

Commit 246ff35

Browse files
Merge branch '4.0'
* 4.0: [YAML] Issue #26065: leading spaces in YAML multi-line string literals [Bridge\PhpUnit] Exit as late as possible [Bridge\PhpUnit] Cleanup BC layer [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener [Lock] Log already-locked errors as "notice" instead of "warning" add context to serialize and deserialize Update Repository Symlink Helper isCsrfTokenValid() replace string by ?string Document explicitly that dotfiles and vcs files are ignored by default [HttpKernel] don't try to wire Request argument with controller.service_arguments Make kernel build time optionally deterministic Use 0 for unlimited expiry [Routing] fix typo Bump default PHPUnit version from 6.3 to 6.5 do not mock the container builder in tests [Cache][WebProfiler] fix collecting cache stats with sub-requests + allow clearing calls
2 parents 427b284 + fa3eacc commit 246ff35

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

Lock.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public function acquire($blocking = false)
8989
return true;
9090
} catch (LockConflictedException $e) {
9191
$this->dirty = false;
92-
$this->logger->warning('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
92+
$this->logger->notice('Failed to acquire the "{resource}" lock. Someone else already acquired the lock.', array('resource' => $this->key));
9393

9494
if ($blocking) {
9595
throw $e;
9696
}
9797

9898
return false;
9999
} catch (\Exception $e) {
100-
$this->logger->warning('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
100+
$this->logger->notice('Failed to acquire the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
101101
throw new LockAcquiringException(sprintf('Failed to acquire the "%s" lock.', $this->key), 0, $e);
102102
}
103103
}
@@ -123,10 +123,10 @@ public function refresh()
123123
$this->logger->info('Expiration defined for "{resource}" lock for "{ttl}" seconds.', array('resource' => $this->key, 'ttl' => $this->ttl));
124124
} catch (LockConflictedException $e) {
125125
$this->dirty = false;
126-
$this->logger->warning('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
126+
$this->logger->notice('Failed to define an expiration for the "{resource}" lock, someone else acquired the lock.', array('resource' => $this->key));
127127
throw $e;
128128
} catch (\Exception $e) {
129-
$this->logger->warning('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
129+
$this->logger->notice('Failed to define an expiration for the "{resource}" lock.', array('resource' => $this->key, 'exception' => $e));
130130
throw new LockAcquiringException(sprintf('Failed to define an expiration for the "%s" lock.', $this->key), 0, $e);
131131
}
132132
}
@@ -148,7 +148,7 @@ public function release()
148148
$this->dirty = false;
149149

150150
if ($this->store->exists($this->key)) {
151-
$this->logger->warning('Failed to release the "{resource}" lock.', array('resource' => $this->key));
151+
$this->logger->notice('Failed to release the "{resource}" lock.', array('resource' => $this->key));
152152
throw new LockReleasingException(sprintf('Failed to release the "%s" lock.', $this->key));
153153
}
154154
}

Tests/LockTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Lock\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Log\LoggerInterface;
1516
use Symfony\Component\Lock\Exception\LockConflictedException;
1617
use Symfony\Component\Lock\Key;
1718
use Symfony\Component\Lock\Lock;
@@ -192,6 +193,35 @@ public function testReleaseThrowsExceptionIfNotWellDeleted()
192193
$lock->release();
193194
}
194195

196+
/**
197+
* @expectedException \Symfony\Component\Lock\Exception\LockReleasingException
198+
*/
199+
public function testReleaseThrowsAndLog()
200+
{
201+
$key = new Key(uniqid(__METHOD__, true));
202+
$store = $this->getMockBuilder(StoreInterface::class)->getMock();
203+
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
204+
$lock = new Lock($key, $store, 10, true);
205+
$lock->setLogger($logger);
206+
207+
$logger->expects($this->atLeastOnce())
208+
->method('notice')
209+
->with('Failed to release the "{resource}" lock.', array('resource' => $key));
210+
211+
$store
212+
->expects($this->once())
213+
->method('delete')
214+
->with($key);
215+
216+
$store
217+
->expects($this->once())
218+
->method('exists')
219+
->with($key)
220+
->willReturn(true);
221+
222+
$lock->release();
223+
}
224+
195225
/**
196226
* @dataProvider provideExpiredDates
197227
*/

0 commit comments

Comments
 (0)