Skip to content

Commit

Permalink
Add a test that demonstrates how to track the states of circuit break…
Browse files Browse the repository at this point in the history
…er (#1829)
  • Loading branch information
martintmk authored and martincostello committed Jan 4, 2024
1 parent a650254 commit c0de5fc
Showing 1 changed file with 47 additions and 0 deletions.
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);
}
}
}

0 comments on commit c0de5fc

Please sign in to comment.