8000 bugfix: pass the already locked error from warning to notice · symfony/symfony@01520a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01520a7

Browse files
author
Amrouche Hamza
committed
bugfix: pass the already locked error from warning to notice
1 parent ae25291 commit 01520a7

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

src/Symfony/Component/Lock/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.1.0
5+
-----
6+
7+
* Add the ability to specify a log level for the lock component.
8+
49
3. 8000 4.0
510
-----
611

src/Symfony/Component/Lock/Lock.php

Lines changed: 7 additions & 9 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,23 +148,21 @@ 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
}
155155

156156
/**
157-
* @return bool
157+
* {@inheritdoc}
158158
*/
159159
public function isExpired()
160160
{
161161
return $this->key->isExpired();
162162
}
163163

164164
/**
165-
* Returns the remaining lifetime.
166-
*
167-
* @return float|null Remaining lifetime in seconds. Null when the lock won't expire.
165+
* {@inheritdoc}
168166
*/
169167
public function getRemainingLifetime()
170168
{

src/Symfony/Component/Lock/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)
0