Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickaël Andrieu committed May 24, 2019
1 parent 0641fd4 commit fcfae84
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Places/ClosedPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/States.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
4 changes: 4 additions & 0 deletions tests/CircuitBreakerWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/SymfonyCircuitBreakerEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fcfae84

Please sign in to comment.