-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce unit-tests for issues fixed in v8
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateSharing_959.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Polly.CircuitBreaker; | ||
|
||
namespace Polly.Core.Tests.Issues; | ||
|
||
public partial class IssuesTests | ||
{ | ||
[Fact] | ||
public void CircuitBreakerStateSharing_959() | ||
{ | ||
var options = new AdvancedCircuitBreakerStrategyOptions | ||
{ | ||
FailureThreshold = 1, | ||
MinimumThroughput = 10 | ||
}; | ||
|
||
// handle int results | ||
options.ShouldHandle.HandleResult(-1); | ||
|
||
// handle string results | ||
options.ShouldHandle.HandleResult("error"); | ||
|
||
// create the strategy | ||
var strategy = new ResilienceStrategyBuilder { TimeProvider = TimeProvider.Object }.AddAdvancedCircuitBreaker(options).Build(); | ||
|
||
// now trigger the circuit breaker by evaluating multiple result types | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
strategy.Execute(_ => -1); | ||
strategy.Execute(_ => "error"); | ||
} | ||
|
||
// now the circuit breaker should be open | ||
strategy.Invoking(s => s.Execute(_ => 0)).Should().Throw<BrokenCircuitException>(); | ||
strategy.Invoking(s => s.Execute(_ => "valid-result")).Should().Throw<BrokenCircuitException>(); | ||
|
||
// now wait | ||
TimeProvider.AdvanceTime(options.BreakDuration); | ||
|
||
// OK, circuit is open now | ||
strategy.Execute(_ => 0); | ||
strategy.Execute(_ => "valid-result"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Polly.Core.Tests.Issues; | ||
|
||
public partial class IssuesTests | ||
{ | ||
private FakeTimeProvider TimeProvider { get; } = new FakeTimeProvider().SetupUtcNow(); | ||
} |