From 8017f2ecc7de4b6cc1585d502e65ea4f56d42051 Mon Sep 17 00:00:00 2001 From: Dmytro Dzubenko Date: Fri, 11 Dec 2020 18:04:16 +0200 Subject: [PATCH] [Lock] Prevent store exception break combined store --- Store/CombinedStore.php | 11 ++++++++--- Tests/Store/CombinedStoreTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Store/CombinedStore.php b/Store/CombinedStore.php index 8810eb0..a7da024 100644 --- a/Store/CombinedStore.php +++ b/Store/CombinedStore.php @@ -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; } diff --git a/Tests/Store/CombinedStoreTest.php b/Tests/Store/CombinedStoreTest.php index c8da617..98240e8 100644 --- a/Tests/Store/CombinedStoreTest.php +++ b/Tests/Store/CombinedStoreTest.php @@ -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)); + } }