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

Skip to content

Commit cee77a9

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

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/Symfony/Component/Lock/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ CHANGELOG
55
-----
66

77
* added the component
8+
* change the warning to notice and errors

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

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