bug #39476 [Lock] Prevent store exception break combined store (dzubchik)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Lock] Prevent store exception break combined store

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? |no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #39470 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

Handle exception to preserve expected behavior - one or multiple stores could be unreachable in a moment and combined store will handle this according to strategy.

Commits
-------

0daff35bae [Lock] Prevent store exception break combined store
This commit is contained in:
Nicolas Grekas 2020-12-14 11:21:44 +01:00
commit 43ab20e4f2
2 changed files with 33 additions and 3 deletions

View File

@ -171,9 +171,14 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
$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;
}

View File

@ -351,4 +351,29 @@ class CombinedStoreTest extends AbstractStoreTest
$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));
}
}