-
-
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.
Add a test that demonstrates how to track the states of circuit break…
…er (#1829)
- Loading branch information
1 parent
a650254
commit c0de5fc
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
test/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateRegistry_1828.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,47 @@ | ||
using Polly.CircuitBreaker; | ||
using Polly.Registry; | ||
|
||
namespace Polly.Core.Tests.Issues; | ||
|
||
public partial class IssuesTests | ||
{ | ||
[Fact] | ||
public void CircuitBreakerStateRegistry_1828() | ||
{ | ||
// Arrange | ||
var states = new ConcurrentBag<CircuitBreakerStateProvider>(); | ||
using var registry = new ResiliencePipelineRegistry<string>(); | ||
|
||
// Act | ||
_ = registry.GetOrAddPipeline("A", builder => | ||
{ | ||
var stateProvider = new CircuitBreakerStateProvider(); | ||
builder.AddCircuitBreaker(new() { StateProvider = stateProvider }); | ||
states.Add(stateProvider); | ||
}); | ||
|
||
_ = registry.GetOrAddPipeline("B", builder => | ||
{ | ||
var stateProvider = new CircuitBreakerStateProvider(); | ||
builder.AddCircuitBreaker(new() { StateProvider = stateProvider }); | ||
states.Add(stateProvider); | ||
}); | ||
|
||
_ = registry.TryAddBuilder("C", (builder, _) => | ||
{ | ||
var stateProvider = new CircuitBreakerStateProvider(); | ||
builder.AddCircuitBreaker(new() { StateProvider = stateProvider }); | ||
states.Add(stateProvider); | ||
}); | ||
|
||
// Assert | ||
states.Should().HaveCount(2); | ||
registry.GetPipeline("C"); | ||
states.Should().HaveCount(3); | ||
|
||
foreach (var state in states) | ||
{ | ||
state.CircuitState.Should().Be(CircuitState.Closed); | ||
} | ||
} | ||
} |