Skip to content

Commit 8017f2e

Browse files
dzubchiknicolas-grekas
authored andcommitted
[Lock] Prevent store exception break combined store
1 parent 25c6703 commit 8017f2e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Store/CombinedStore.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ public function exists(Key $key)
171171
$storesCount = \count($this->stores);
172172

173173
foreach ($this->stores as $store) {
174-
if ($store->exists($key)) {
175-
++$successCount;
176-
} else {
174+
try {
175+
if ($store->exists($key)) {
176+
++$successCount;
177+
} else {
178+
++$failureCount;
179+
}
180+
} catch (\Exception $e) {
181+
$this->logger->debug('One store failed to check the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
177182
++$failureCount;
178183
}
179184

Tests/Store/CombinedStoreTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,29 @@ public function testDeleteDontStopOnFailure()
351351

352352
$this->store->delete($key);
353353
}
354+
355+
public function testExistsDontStopOnFailure()
356+
{
357+
$key = new Key(uniqid(__METHOD__, true));
358+
359+
$this->strategy
360+
->expects($this->any())
361+
->method('canBeMet')
362+
->willReturn(true);
363+
$this->strategy
364+
->expects($this->any())
365+
->method('isMet')
366+
->willReturn(false);
367+
$this->store1
368+
->expects($this->once())
369+
->method('exists')
370+
->willThrowException(new \Exception());
371+
$this->store2
372+
->expects($this->once())
373+
->method('exists')
374+
->with($key)
375+
->willReturn(false);
376+
377+
$this->assertFalse($this->store->exists($key));
378+
}
354379
}

0 commit comments

Comments
 (0)