Skip to content

Commit

Permalink
[Lock] Prevent store exception break combined store
Browse files Browse the repository at this point in the history
  • Loading branch information
dzubchik authored and nicolas-grekas committed Dec 14, 2020
1 parent 25c6703 commit 8017f2e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Store/CombinedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ public function exists(Key $key)
$storesCount = \count($this->stores);

foreach ($this->stores as $store) {
if ($store->exists($key)) {
++$successCount;
} else {
try {
if ($store->exists($key)) {
++$successCount;
} else {
++$failureCount;
}
} catch (\Exception $e) {
$this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
++$failureCount;
}

Expand Down
25 changes: 25 additions & 0 deletions Tests/Store/CombinedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,29 @@ public function testDeleteDontStopOnFailure()

$this->store->delete($key);
}

public function testExistsDontStopOnFailure()
{
$key = new Key(uniqid(__METHOD__, true));

$this->strategy
->expects($this->any())
->method('canBeMet')
->willReturn(true);
$this->strategy
->expects($this->any())
->method('isMet')
->willReturn(false);
$this->store1
->expects($this->once())
->method('exists')
->willThrowException(new \Exception());
$this->store2
->expects($this->once())
->method('exists')
->with($key)
->willReturn(false);

$this->assertFalse($this->store->exists($key));
}
}

0 comments on commit 8017f2e

Please sign in to comment.