Skip to content

Commit

Permalink
Allow isolate CircuitBreakerManualControl using constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Jul 26, 2023
1 parent 2410e68 commit 3dc9160
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Polly.Core/CircuitBreaker/CircuitBreakerManualControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ public sealed class CircuitBreakerManualControl : IDisposable
private readonly HashSet<Func<ResilienceContext, Task>> _onReset = new();
private bool _isolated;

/// <summary>
/// Initializes a new instance of the <see cref="CircuitBreakerManualControl"/> class.
/// </summary>
public CircuitBreakerManualControl()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="CircuitBreakerManualControl"/> class.
/// </summary>
/// <param name="isIsolated">Determines whether the circit breaker is isolated immediately after construction.</param>
public CircuitBreakerManualControl(bool isIsolated) => _isolated = isIsolated;

internal void Initialize(Func<ResilienceContext, Task> onIsolate, Func<ResilienceContext, Task> onReset, Action onDispose)
{
_onDispose.Add(onDispose);
Expand Down
1 change: 1 addition & 0 deletions src/Polly.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Polly.CircuitBreaker.BrokenCircuitException<TResult>.BrokenCircuitException(TRes
Polly.CircuitBreaker.BrokenCircuitException<TResult>.Result.get -> TResult
Polly.CircuitBreaker.CircuitBreakerManualControl
Polly.CircuitBreaker.CircuitBreakerManualControl.CircuitBreakerManualControl() -> void
Polly.CircuitBreaker.CircuitBreakerManualControl.CircuitBreakerManualControl(bool isIsolated) -> void
Polly.CircuitBreaker.CircuitBreakerManualControl.CloseAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Polly.CircuitBreaker.CircuitBreakerManualControl.Dispose() -> void
Polly.CircuitBreaker.CircuitBreakerManualControl.IsolateAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ namespace Polly.Core.Tests.CircuitBreaker;

public class CircuitBreakerManualControlTests
{
[InlineData(true)]
[InlineData(false)]
[Theory]
public void Ctor_Isolated(bool isolated)
{
using var control = new CircuitBreakerManualControl(isolated);
var isolateCalled = false;

control.Initialize(
c =>
{
c.IsSynchronous.Should().BeTrue();
isolateCalled = true;
return Task.CompletedTask;
},
_ => Task.CompletedTask,
() => { });

isolateCalled.Should().Be(isolated);
}

[InlineData(true)]
[InlineData(false)]
[Theory]
Expand Down

0 comments on commit 3dc9160

Please sign in to comment.