diff --git a/src/Places/ClosedPlace.php b/src/Places/ClosedPlace.php index 589dd95..cac4cd0 100644 --- a/src/Places/ClosedPlace.php +++ b/src/Places/ClosedPlace.php @@ -7,8 +7,8 @@ /** * The circuit initially starts closed. When the circuit is closed: * - * The circuit-breaker executes actions placed through it, measuring the faults and successes of those actions. - * If the faults exceed a certain threshold, the circuit will break (open). + * The circuit-breaker executes actions placed through it, measuring the failures and successes of those actions. + * If the failures exceed a certain threshold, the circuit will break (open). */ final class ClosedPlace extends AbstractPlace { diff --git a/src/States.php b/src/States.php index 9a37577..9263240 100644 --- a/src/States.php +++ b/src/States.php @@ -30,7 +30,7 @@ final class States /** * Once isolated, the circuit breaker stays in OPEN state and - * won't accepts any requests, even when the threshold is reached. + * won't accept any requests, even when the threshold is reached. */ const ISOLATED_STATE = 'ISOLATED'; } diff --git a/tests/CircuitBreakerWorkflowTest.php b/tests/CircuitBreakerWorkflowTest.php index a498c84..7952402 100644 --- a/tests/CircuitBreakerWorkflowTest.php +++ b/tests/CircuitBreakerWorkflowTest.php @@ -121,6 +121,10 @@ public function testOnceCircuitBreakerIsIsolatedNoTrialsAreDone(CircuitBreaker $ $this->assertSame('{}', $response); $this->assertTrue($circuitBreaker->isIsolated()); } + + $circuitBreaker->reset('https://httpbin.org/get/foo'); + + $this->assertTrue($circuitBreaker->isClosed()); } /** diff --git a/tests/SymfonyCircuitBreakerEventsTest.php b/tests/SymfonyCircuitBreakerEventsTest.php index bbab39f..07c2b7f 100644 --- a/tests/SymfonyCircuitBreakerEventsTest.php +++ b/tests/SymfonyCircuitBreakerEventsTest.php @@ -52,6 +52,38 @@ function () { $this->assertSame('resiliency.opening', $invocations[3]->getParameters()[0]); } + public function testCircuitBreakerEventsOnIsolationAndResetActions(): void + { + $service = 'https://httpbin.org/get/foobaz'; + $circuitBreaker = $this->createCircuitBreaker(); + + $circuitBreaker->call( + $service, + function () { + return '{}'; + } + ); + + $circuitBreaker->isolate($service); + + /** + * The circuit breaker is now isolated and + * the related event has been dispatched + */ + $invocations = $this->spy->getInvocations(); + $this->assertCount(5, $invocations); + $this->assertSame('resiliency.isolating', $invocations[4]->getParameters()[0]); + + /* + * And now we reset the circuit breaker! + * The related event must be dispatched + */ + $circuitBreaker->reset($service); + $invocations = $this->spy->getInvocations(); + $this->assertCount(6, $invocations); + $this->assertSame('resiliency.resetting', $invocations[5]->getParameters()[0]); + } + private function createCircuitBreaker(): CircuitBreaker { $system = $this->getSystem();