diff --git a/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs b/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs index 97c5abaf65c..316416272e8 100644 --- a/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs +++ b/src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs @@ -62,7 +62,7 @@ public async Task Should_call_onBulkheadRejected_with_passed_context() Func onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; }; using (var bulkhead = Policy.BulkheadAsync(1, onRejectedAsync)) - { + { TaskCompletionSource tcs = new TaskCompletionSource(); using (CancellationTokenSource cancellationSource = new CancellationTokenSource()) { diff --git a/src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs b/src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs index 3100343ba2e..0c126fe0eff 100644 --- a/src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs +++ b/src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs @@ -62,7 +62,7 @@ public void Should_call_onBulkheadRejected_with_passed_context() Action onRejected = ctx => { contextPassedToOnRejected = ctx; }; using (BulkheadPolicy bulkhead = Policy.Bulkhead(1, onRejected)) - { + { TaskCompletionSource tcs = new TaskCompletionSource(); using (CancellationTokenSource cancellationSource = new CancellationTokenSource()) { diff --git a/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs b/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs index 730baa2f61a..427b786c320 100644 --- a/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs +++ b/src/Polly.Specs/Caching/SerializingCacheProviderAsyncSpecs.cs @@ -11,7 +11,7 @@ namespace Polly.Specs.Caching; public class AsyncSerializingCacheProviderSpecs { - #region Object-to-TSerialized serializer + #region Object-to-TSerialized serializer [Fact] public void Single_generic_constructor_should_throw_on_no_wrapped_cache_provider() diff --git a/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs b/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs index 28b9627536e..185951b381d 100644 --- a/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs +++ b/src/Polly.Specs/Caching/SerializingCacheProviderSpecs.cs @@ -9,7 +9,7 @@ namespace Polly.Specs.Caching; public class SerializingCacheProviderSpecs { - #region Object-to-TSerialized serializer + #region Object-to-TSerialized serializer [Fact] public void Single_generic_constructor_should_throw_on_no_wrapped_cache_provider() diff --git a/src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs b/src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs index 3504018b616..906897b5b20 100644 --- a/src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs +++ b/src/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs @@ -82,9 +82,9 @@ public void Should_throw_if_timeslice_duration_is_less_than_resolution_of_circui Action action = () => Policy .Handle() .AdvancedCircuitBreaker( - 0.5, - TimeSpan.FromMilliseconds(20).Add(TimeSpan.FromTicks(-1)), - 4, + 0.5, + TimeSpan.FromMilliseconds(20).Add(TimeSpan.FromTicks(-1)), + 4, TimeSpan.FromSeconds(30)); action.Should().Throw() @@ -164,8 +164,8 @@ public void Should_initialise_to_closed_state() #region Tests that are independent from health metrics implementation - // Tests on the AdvancedCircuitBreaker operation typically use a breaker: - // - with a failure threshold of >=50%, + // Tests on the AdvancedCircuitBreaker operation typically use a breaker: + // - with a failure threshold of >=50%, // - and a throughput threshold of 4 // - across a ten-second period. // These provide easy values for testing for failure and throughput thresholds each being met and non-met, in combination. @@ -244,8 +244,8 @@ public void Should_not_open_circuit_if_exceptions_raised_are_not_one_of_the_spec #region With sample duration higher than 199 ms so that multiple windows are used - // Tests on the AdvancedCircuitBreaker operation typically use a breaker: - // - with a failure threshold of >=50%, + // Tests on the AdvancedCircuitBreaker operation typically use a breaker: + // - with a failure threshold of >=50%, // - and a throughput threshold of 4 // - across a ten-second period. // These provide easy values for testing for failure and throughput thresholds each being met and non-met, in combination. @@ -838,8 +838,8 @@ public void Should_not_open_circuit_if_failures_at_end_of_last_timeslice_and_fai // Setting the time to just barely into the new timeslice SystemClock.UtcNow = () => time.Add(samplingDuration); - // A third failure occurs just at the beginning of the new timeslice making - // the number of failures above the failure threshold. However, the throughput is + // A third failure occurs just at the beginning of the new timeslice making + // the number of failures above the failure threshold. However, the throughput is // below the minimum threshold as to open the circuit. breaker.Invoking(x => x.RaiseException()) .Should().Throw(); @@ -898,8 +898,8 @@ public void Should_open_circuit_if_failures_in_second_window_of_last_timeslice_a #region With sample duration at 199 ms so that only a single window is used - // These tests on AdvancedCircuitBreaker operation typically use a breaker: - // - with a failure threshold of >=50%, + // These tests on AdvancedCircuitBreaker operation typically use a breaker: + // - with a failure threshold of >=50%, // - and a throughput threshold of 4 // - across a 199ms period. // These provide easy values for testing for failure and throughput thresholds each being met and non-met, in combination. @@ -1258,7 +1258,7 @@ public void Should_not_open_circuit_if_failures_at_end_of_last_timeslice_below_f // Setting the time to just barely into the new timeslice SystemClock.UtcNow = () => time.Add(samplingDuration); - // This failure does not open the circuit, because a new duration should have + // This failure does not open the circuit, because a new duration should have // started and with such low sampling duration, windows should not be used. breaker.Invoking(x => x.RaiseException()) .Should().Throw(); @@ -1413,7 +1413,7 @@ public void Should_open_circuit_again_after_the_specified_duration_has_passed_if breaker.Invoking(x => x.RaiseException()) .Should().Throw(); breaker.CircuitState.Should().Be(CircuitState.Open); - + } [Fact] @@ -1483,7 +1483,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -1522,7 +1522,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -1569,7 +1569,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exceptions raised, circuit is now open. + // exceptions raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -1582,7 +1582,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ TimeSpan testTimeoutToExposeDeadlocks = TimeSpan.FromSeconds(5); using (ManualResetEvent permitSecondExecutionAttempt = new ManualResetEvent(false)) using (ManualResetEvent permitFirstExecutionEnd = new ManualResetEvent(false)) - { + { bool? firstDelegateExecutedInHalfOpenState = null; bool? secondDelegateExecutedInHalfOpenState = null; bool? secondDelegateRejectedInHalfOpenState = null; @@ -1642,7 +1642,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should not have been permitted. // - Second execution attempt should have been rejected with HalfOpen state as cause. @@ -1674,7 +1674,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -1688,7 +1688,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ TimeSpan testTimeoutToExposeDeadlocks = TimeSpan.FromSeconds(5); using (ManualResetEvent permitSecondExecutionAttempt = new ManualResetEvent(false)) using (ManualResetEvent permitFirstExecutionEnd = new ManualResetEvent(false)) - { + { bool? firstDelegateExecutedInHalfOpenState = null; bool? secondDelegateExecutedInHalfOpenState = null; bool? secondDelegateRejectedInHalfOpenState = null; @@ -1750,7 +1750,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should have been permitted, one breakDuration later. firstDelegateExecutedInHalfOpenState.Should().BeTrue(); @@ -1997,7 +1997,7 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub onBreakCalled.Should().Be(1); - // call through circuit when already broken - should not retrigger onBreak + // call through circuit when already broken - should not retrigger onBreak breaker.Invoking(x => x.RaiseException()) .Should().Throw(); @@ -2491,7 +2491,7 @@ public void Should_open_circuit_with_timespan_maxvalue_if_manual_override_open() var time = 1.January(2000); SystemClock.UtcNow = () => time; - + CircuitBreakerPolicy breaker = Policy .Handle() .AdvancedCircuitBreaker( diff --git a/src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs b/src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs index 4b1fe9dec51..5ffe6992704 100644 --- a/src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs +++ b/src/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs @@ -324,7 +324,7 @@ public async Task Should_only_allow_single_execution_on_first_entering_halfopen_ await breaker.Awaiting(x => x.RaiseExceptionAsync()) .Should().ThrowAsync(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -355,13 +355,13 @@ public async Task Should_allow_single_execution_per_break_duration_in_halfopen_s await breaker.Awaiting(x => x.RaiseExceptionAsync()) .Should().ThrowAsync(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open SystemClock.UtcNow = () => time.Add(durationOfBreak); breaker.CircuitState.Should().Be(CircuitState.HalfOpen); - + // OnActionPreExecute() should permit first execution. breaker._breakerController.Invoking(c => c.OnActionPreExecute()).Should().NotThrow(); @@ -394,7 +394,7 @@ public async Task Should_only_allow_single_execution_on_first_entering_halfopen_ await breaker.Awaiting(x => x.RaiseExceptionAsync()) .Should().ThrowAsync(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -469,7 +469,7 @@ await breaker.ExecuteAsync(async () => firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should not have been permitted. // - Second execution attempt should have been rejected with HalfOpen state as cause. @@ -493,7 +493,7 @@ public async Task Should_allow_single_execution_per_break_duration_in_halfopen_s await breaker.Awaiting(x => x.RaiseExceptionAsync()) .Should().ThrowAsync(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -571,7 +571,7 @@ await breaker.ExecuteAsync(async () => firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should have been permitted, one breakDuration later. firstDelegateExecutedInHalfOpenState.Should().BeTrue(); @@ -772,7 +772,7 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync()) breaker.CircuitState.Should().Be(CircuitState.Open); onBreakCalled.Should().Be(1); - // call through circuit when already broken - should not retrigger onBreak + // call through circuit when already broken - should not retrigger onBreak await breaker.Awaiting(x => x.RaiseExceptionAsync()) .Should().ThrowAsync(); diff --git a/src/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs b/src/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs index b6039630023..2dade8fd715 100644 --- a/src/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs +++ b/src/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs @@ -258,7 +258,7 @@ public void Should_open_circuit_again_after_the_specified_duration_has_passed_if breaker.CircuitState.Should().Be(CircuitState.Open); breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - + } [Fact] @@ -322,7 +322,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -353,7 +353,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -392,7 +392,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -405,7 +405,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ TimeSpan testTimeoutToExposeDeadlocks = TimeSpan.FromSeconds(5); using (ManualResetEvent permitSecondExecutionAttempt = new ManualResetEvent(false)) using (ManualResetEvent permitFirstExecutionEnd = new ManualResetEvent(false)) - { + { bool? firstDelegateExecutedInHalfOpenState = null; bool? secondDelegateExecutedInHalfOpenState = null; bool? secondDelegateRejectedInHalfOpenState = null; @@ -465,7 +465,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should not have been permitted. // - Second execution attempt should have been rejected with HalfOpen state as cause. @@ -490,7 +490,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.Invoking(x => x.RaiseException()) .Should().Throw(); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -566,7 +566,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should have been permitted, one breakDuration later. firstDelegateExecutedInHalfOpenState.Should().BeTrue(); @@ -766,7 +766,7 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub breaker.CircuitState.Should().Be(CircuitState.Open); onBreakCalled.Should().Be(1); - // call through circuit when already broken - should not retrigger onBreak + // call through circuit when already broken - should not retrigger onBreak breaker.Invoking(x => x.RaiseException()) .Should().Throw(); @@ -789,7 +789,7 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub TimeSpan testTimeoutToExposeDeadlocks = TimeSpan.FromSeconds(5); using (ManualResetEvent permitLongRunningExecutionToReturnItsFailure = new ManualResetEvent(false)) using (ManualResetEvent permitMainThreadToOpenCircuit = new ManualResetEvent(false)) - { + { Task longRunningExecution = Task.Factory.StartNew(() => { breaker.CircuitState.Should().Be(CircuitState.Closed); @@ -833,7 +833,7 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub } [Fact] - public void Should_call_onreset_when_automatically_closing_circuit_but_not_when_halfopen() + public void Should_call_onreset_when_automatically_closing_circuit_but_not_when_halfopen() { int onBreakCalled = 0; int onResetCalled = 0; diff --git a/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultMixedResultExceptionSpecs.cs b/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultMixedResultExceptionSpecs.cs index bdd320ef772..d4cbdc77e22 100644 --- a/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultMixedResultExceptionSpecs.cs +++ b/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultMixedResultExceptionSpecs.cs @@ -306,7 +306,7 @@ public void Should_open_circuit_with_the_last_handled_result_after_specified_num breaker.CircuitState.Should().Be(CircuitState.Open); } - + [Fact] public void Should_not_open_circuit_if_result_raised_or_exception_thrown_is_not_one_of_the_handled_results_or_exceptions() { diff --git a/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs b/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs index 0516e371075..e8328db5edb 100644 --- a/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs +++ b/src/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs @@ -387,7 +387,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.RaiseResultSequence(ResultPrimitive.Fault) .Should().Be(ResultPrimitive.Fault); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -418,7 +418,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.RaiseResultSequence(ResultPrimitive.Fault) .Should().Be(ResultPrimitive.Fault); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -457,7 +457,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ breaker.RaiseResultSequence(ResultPrimitive.Fault) .Should().Be(ResultPrimitive.Fault); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -533,7 +533,7 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should not have been permitted. // - Second execution attempt should have been rejected with HalfOpen state as cause. @@ -557,7 +557,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ breaker.RaiseResultSequence(ResultPrimitive.Fault) .Should().Be(ResultPrimitive.Fault); - // exception raised, circuit is now open. + // exception raised, circuit is now open. breaker.CircuitState.Should().Be(CircuitState.Open); // break duration passes, circuit now half open @@ -636,7 +636,7 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__ firstExecution.Status.Should().Be(TaskStatus.RanToCompletion); secondExecution.Status.Should().Be(TaskStatus.RanToCompletion); - // Assert: + // Assert: // - First execution should have been permitted and executed under a HalfOpen state // - Second overlapping execution in halfopen state should have been permitted, one breakDuration later. firstDelegateExecutedInHalfOpenState.Should().BeTrue(); @@ -838,7 +838,7 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub breaker.CircuitState.Should().Be(CircuitState.Open); onBreakCalled.Should().Be(1); - // call through circuit when already broken - should not retrigger onBreak + // call through circuit when already broken - should not retrigger onBreak breaker.Invoking(x => x.Execute(() => ResultPrimitive.Good)) .Should().Throw(); diff --git a/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs b/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs index 406cd95f8e8..ae6119bffb0 100644 --- a/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs +++ b/src/Polly.Specs/Helpers/Caching/StubCacheProvider.cs @@ -49,7 +49,7 @@ public void Put(string key, object value, Ttl ttl) #region Naive async-over-sync implementation - // Intentionally naive async-over-sync implementation. Its purpose is to be the simplest thing to support tests of the CachePolicyAsync and CacheEngineAsync, not to be a usable implementation of IAsyncCacheProvider. + // Intentionally naive async-over-sync implementation. Its purpose is to be the simplest thing to support tests of the CachePolicyAsync and CacheEngineAsync, not to be a usable implementation of IAsyncCacheProvider. public Task<(bool, object)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { return Task.FromResult(TryGet(key)); diff --git a/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs b/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs index a2f563e185f..7e2db7938e5 100644 --- a/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs +++ b/src/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs @@ -33,7 +33,7 @@ public void Put(string key, object value, Ttl ttl) #region Naive async-over-sync implementation - // Intentionally naive async-over-sync implementation. Its purpose is to be the simplest thing to support tests of the CachePolicyAsync and CacheEngineAsync, not to be a usable implementation of IAsyncCacheProvider. + // Intentionally naive async-over-sync implementation. Its purpose is to be the simplest thing to support tests of the CachePolicyAsync and CacheEngineAsync, not to be a usable implementation of IAsyncCacheProvider. public Task<(bool, object)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext) { return Task.FromResult(TryGet(key)); diff --git a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandlePolicy.cs b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandlePolicy.cs index f996124ccc1..d617d3dfca1 100644 --- a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandlePolicy.cs +++ b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandlePolicy.cs @@ -14,13 +14,13 @@ internal AddBehaviourIfHandlePolicy(Action behaviourIfHandle, PolicyB } protected override TResult Implementation( - Func action, - Context context, + Func action, + Context context, CancellationToken cancellationToken) { return AddBehaviourIfHandleEngine.Implementation( ExceptionPredicates, - ResultPredicates.None, + ResultPredicates.None, outcome => _behaviourIfHandle(outcome.Exception), action, context, diff --git a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs index 9493cb0c8de..badfe1f0f32 100644 --- a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs +++ b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs @@ -8,7 +8,7 @@ internal class AsyncAddBehaviourIfHandlePolicy : AsyncPolicy private readonly Func _behaviourIfHandle; internal AsyncAddBehaviourIfHandlePolicy( - Func behaviourIfHandle, + Func behaviourIfHandle, PolicyBuilder policyBuilder) : base(policyBuilder) { diff --git a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandleSyntax.cs b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandleSyntax.cs index b450a85ce8a..4911ac63dbf 100644 --- a/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandleSyntax.cs +++ b/src/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandleSyntax.cs @@ -6,7 +6,7 @@ namespace Polly.Specs.Helpers.Custom.AddBehaviourIfHandle; internal static class AsyncAddBehaviourIfHandleSyntax { internal static AsyncAddBehaviourIfHandlePolicy WithBehaviourAsync( - this PolicyBuilder policyBuilder, + this PolicyBuilder policyBuilder, Func behaviourIfHandle) { if (behaviourIfHandle == null) throw new ArgumentNullException(nameof(behaviourIfHandle)); diff --git a/src/Polly.Specs/Helpers/Custom/PreExecute/PreExecuteEngine.cs b/src/Polly.Specs/Helpers/Custom/PreExecute/PreExecuteEngine.cs index 30313751e62..08627e6c0b2 100644 --- a/src/Polly.Specs/Helpers/Custom/PreExecute/PreExecuteEngine.cs +++ b/src/Polly.Specs/Helpers/Custom/PreExecute/PreExecuteEngine.cs @@ -7,8 +7,8 @@ internal static class PreExecuteEngine { internal static void Implementation( Action preExecute, - Action action, - Context context, + Action action, + Context context, CancellationToken cancellationToken) { preExecute?.Invoke(); diff --git a/src/Polly.Specs/Helpers/PolicyTResultExtensions.cs b/src/Polly.Specs/Helpers/PolicyTResultExtensions.cs index 18b90d316f8..39acc351e7c 100644 --- a/src/Polly.Specs/Helpers/PolicyTResultExtensions.cs +++ b/src/Polly.Specs/Helpers/PolicyTResultExtensions.cs @@ -13,7 +13,7 @@ public static TResult RaiseResultSequence(this Policy policy, return policy.RaiseResultSequence(resultsToRaise.ToList()); } - public static TResult RaiseResultSequence(this Policy policy, IEnumerable resultsToRaise) + public static TResult RaiseResultSequence(this Policy policy, IEnumerable resultsToRaise) { using (var enumerator = resultsToRaise.GetEnumerator()) { diff --git a/src/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs b/src/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs index c6ada99be00..d53ae3f4755 100644 --- a/src/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs +++ b/src/Polly.Specs/PolicyContextAndKeyAsyncSpecs.cs @@ -62,7 +62,7 @@ public void PolicyKey_property_should_be_non_null_or_empty_if_not_explicitly_con public void PolicyKey_property_should_start_with_policy_type_if_not_explicitly_configured() { var policy = Policy.Handle().RetryAsync(); - + policy.PolicyKey.Should().StartWith("AsyncRetry"); } diff --git a/src/Polly.Specs/RateLimit/AsyncRateLimitPolicySpecs.cs b/src/Polly.Specs/RateLimit/AsyncRateLimitPolicySpecs.cs index addb68a7eff..ce421ebe107 100644 --- a/src/Polly.Specs/RateLimit/AsyncRateLimitPolicySpecs.cs +++ b/src/Polly.Specs/RateLimit/AsyncRateLimitPolicySpecs.cs @@ -25,7 +25,7 @@ protected override IRateLimitPolicy GetPolicyViaSyntax(int numberOfExecutions, T { return Policy.RateLimitAsync(numberOfExecutions, perTimeSpan, maxBurst); } - + protected override (bool, TimeSpan) TryExecuteThroughPolicy(IRateLimitPolicy policy) { if (policy is AsyncRateLimitPolicy typedPolicy) diff --git a/src/Polly.Specs/Registry/PolicyRegistrySpecs.cs b/src/Polly.Specs/Registry/PolicyRegistrySpecs.cs index bfa28e6f9c7..df1815c8e6f 100644 --- a/src/Polly.Specs/Registry/PolicyRegistrySpecs.cs +++ b/src/Polly.Specs/Registry/PolicyRegistrySpecs.cs @@ -68,7 +68,7 @@ public void Should_be_able_to_add_Policy_by_interface_using_Add() _registry.Add>(key2, policy2); _registry.Count.Should().Be(2); } - + [Fact] public void Should_be_able_to_add_Policy_using_Indexer() { @@ -100,7 +100,7 @@ public void Should_be_able_to_add_PolicyTResult_using_Indexer() _registry[key2] = policy2; _registry.Count.Should().Be(2); } - + [Fact] public void Should_not_be_able_to_add_Policy_with_duplicate_key_using_Add() { @@ -145,7 +145,7 @@ public void Should_be_able_to_overwrite_existing_PolicyTResult_if_key_exists_whe _registry.Get>(key).Should().BeSameAs(policy_new); } - + [Fact] public void Should_throw_when_adding_Policy_using_Add_when_key_is_null() { @@ -443,7 +443,7 @@ public void Should_throw_when_checking_if_key_exists_when_key_is_null() } #endregion - #region Tests for the constructor + #region Tests for the constructor [Fact] public void Constructor_Called_With_A_Registry_Parameter_Should_Assign_The_Passed_In_Registry_To_The_Registry_Field() { diff --git a/src/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs b/src/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs index eb6a233ae7a..976aab55b13 100644 --- a/src/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs +++ b/src/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs @@ -253,7 +253,7 @@ public void Should_throw_when_checking_if_key_exists_when_key_is_null() .Should().Throw(); } #endregion - + #region Tests for the GetEnumerator method [Fact] diff --git a/src/Polly.Specs/Retry/RetrySpecs.cs b/src/Polly.Specs/Retry/RetrySpecs.cs index e2ac616708d..88668acc065 100644 --- a/src/Polly.Specs/Retry/RetrySpecs.cs +++ b/src/Polly.Specs/Retry/RetrySpecs.cs @@ -18,7 +18,7 @@ public void Should_throw_when_retry_count_is_less_than_zero_without_context() Action policy = () => Policy .Handle() .Retry(-1, onRetry); - + policy.Should().Throw().And .ParamName.Should().Be("retryCount"); } @@ -95,7 +95,7 @@ public void Should_not_throw_when_specified_exception_thrown_less_number_of_time policy.Invoking(x => x.RaiseException()) .Should().NotThrow(); } - + [Fact] public void Should_not_throw_when_one_of_the_specified_exceptions_thrown_less_number_of_times_than_retry_count() { @@ -107,7 +107,7 @@ public void Should_not_throw_when_one_of_the_specified_exceptions_thrown_less_nu policy.Invoking(x => x.RaiseException()) .Should().NotThrow(); } - + [Fact] public void Should_throw_when_specified_exception_thrown_more_times_then_retry_count() { @@ -118,7 +118,7 @@ public void Should_throw_when_specified_exception_thrown_more_times_then_retry_c policy.Invoking(x => x.RaiseException(3 + 1)) .Should().Throw(); } - + [Fact] public void Should_throw_when_one_of_the_specified_exceptions_are_thrown_more_times_then_retry_count() { @@ -130,7 +130,7 @@ public void Should_throw_when_one_of_the_specified_exceptions_are_thrown_more_ti policy.Invoking(x => x.RaiseException(3 + 1)) .Should().Throw(); } - + [Fact] public void Should_throw_when_exception_thrown_is_not_the_specified_exception_type() { @@ -382,7 +382,7 @@ public void Should_call_onretry_with_the_passed_context_when_execute_and_capture .Handle() .Retry((_, _, context) => contextData = context); - policy.Invoking(p => p.ExecuteAndCapture(_ => { throw new DivideByZeroException();}, + policy.Invoking(p => p.ExecuteAndCapture(_ => { throw new DivideByZeroException();}, new { key1 = "value1", key2 = "value2" }.AsDictionary())) .Should().NotThrow(); @@ -437,7 +437,7 @@ public void Should_create_new_context_for_each_call_to_execute_and_capture() .Handle() .Retry((_, _, context) => contextValue = context["key"].ToString()); - policy.Invoking(p => p.ExecuteAndCapture(_ => throw new DivideByZeroException(), + policy.Invoking(p => p.ExecuteAndCapture(_ => throw new DivideByZeroException(), new { key = "original_value" }.AsDictionary())) .Should().NotThrow(); diff --git a/src/Polly.Specs/Retry/RetryTResultSpecs.cs b/src/Polly.Specs/Retry/RetryTResultSpecs.cs index b51cb3ca968..ab447b6cae4 100644 --- a/src/Polly.Specs/Retry/RetryTResultSpecs.cs +++ b/src/Polly.Specs/Retry/RetryTResultSpecs.cs @@ -264,7 +264,7 @@ public void Should_call_onretry_with_the_passed_context() .Retry((_, _, context) => contextData = context); policy.RaiseResultSequence( - new { key1 = "value1", key2 = "value2" }.AsDictionary(), + new { key1 = "value1", key2 = "value2" }.AsDictionary(), ResultPrimitive.Fault, ResultPrimitive.Good ) .Should().Be(ResultPrimitive.Good); @@ -288,8 +288,8 @@ public void Should_call_onretry_with_the_passed_context_when_execute_and_capture ResultPrimitive.Fault, ResultPrimitive.Good ); - result.Should().BeEquivalentTo(new - { + result.Should().BeEquivalentTo(new + { Outcome = OutcomeType.Successful, FinalException = (Exception)null, ExceptionType = (ExceptionType?)null, diff --git a/src/Polly.Specs/Retry/RetryTResultSpecsAsync.cs b/src/Polly.Specs/Retry/RetryTResultSpecsAsync.cs index d937e3e694a..da927ca7c34 100644 --- a/src/Polly.Specs/Retry/RetryTResultSpecsAsync.cs +++ b/src/Polly.Specs/Retry/RetryTResultSpecsAsync.cs @@ -422,7 +422,7 @@ public async Task Should_not_call_onretry_when_retry_count_is_zero_with_context( [Fact] public async Task Should_wait_asynchronously_for_async_onretry_delegate() { - // This test relates to https://github.com/App-vNext/Polly/issues/107. + // This test relates to https://github.com/App-vNext/Polly/issues/107. // An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: http://blogs.msdn.com/b/pfxteam/archive/2012/02/08/10265476.aspx // If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' would/could occur before onRetry execution had completed. // This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences. @@ -449,7 +449,7 @@ public async Task Should_wait_asynchronously_for_async_onretry_delegate() while (executeDelegateInvocationsWhenOnRetryExits == 0) { } // Wait for the onRetry delegate to complete. - executeDelegateInvocationsWhenOnRetryExits.Should().Be(1); // If the async onRetry delegate is genuinely awaited, only one execution of the .Execute delegate should have occurred by the time onRetry completes. If the async onRetry delegate were instead assigned to an Action<...>, then onRetry will return, and the second action execution will commence, before await Task.Delay() completes, leaving executeDelegateInvocationsWhenOnRetryExits == 2. + executeDelegateInvocationsWhenOnRetryExits.Should().Be(1); // If the async onRetry delegate is genuinely awaited, only one execution of the .Execute delegate should have occurred by the time onRetry completes. If the async onRetry delegate were instead assigned to an Action<...>, then onRetry will return, and the second action execution will commence, before await Task.Delay() completes, leaving executeDelegateInvocationsWhenOnRetryExits == 2. executeDelegateInvocations.Should().Be(2); } @@ -755,6 +755,6 @@ public async Task Should_report_cancellation_after_faulting_action_execution_and attemptsInvoked.Should().Be(1); } - + #endregion } diff --git a/src/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs b/src/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs index 739e4c82d9c..986a6a8f43e 100644 --- a/src/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs +++ b/src/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs @@ -101,14 +101,14 @@ public void Should_not_throw_regardless_of_how_many_times_one_of_the_specified_e public void Should_throw_when_exception_thrown_is_not_the_specified_exception_type() { Func provider = _ => TimeSpan.Zero; - + var policy = Policy .Handle() .WaitAndRetryForever(provider); policy.Invoking(x => x.RaiseException()) .Should().Throw(); - } + } [Fact] public void Should_throw_when_exception_thrown_is_not_one_of_the_specified_exception_types() @@ -123,7 +123,7 @@ public void Should_throw_when_exception_thrown_is_not_one_of_the_specified_excep policy.Invoking(x => x.RaiseException()) .Should().Throw(); } - + [Fact] public void Should_throw_when_specified_exception_predicate_is_not_satisfied() { @@ -163,7 +163,7 @@ public void Should_not_throw_when_specified_exception_predicate_is_satisfied() policy.Invoking(x => x.RaiseException()) .Should().NotThrow(); } - + [Fact] public void Should_not_throw_when_one_of_the_specified_exception_predicates_are_satisfied() { @@ -260,7 +260,7 @@ public void Should_create_new_context_for_each_call_to_policy() var policy = Policy .Handle() .WaitAndRetryForever( - provider, + provider, (_, _, context) => contextValue = context["key"].ToString()); policy.RaiseException( @@ -355,7 +355,7 @@ public void Should_be_able_to_pass_retry_duration_from_execution_to_sleepDuratio failedOnce = true; throw new DivideByZeroException(); } - }, + }, new {RetryAfter = defaultRetryAfter}.AsDictionary() // Can also set an initial value for RetryAfter, in the Context passed into the call. ); diff --git a/src/Polly.Specs/Timeout/TimeoutSpecs.cs b/src/Polly.Specs/Timeout/TimeoutSpecs.cs index 9e87f005cec..df7c8c69cd3 100644 --- a/src/Polly.Specs/Timeout/TimeoutSpecs.cs +++ b/src/Polly.Specs/Timeout/TimeoutSpecs.cs @@ -362,7 +362,7 @@ public void Should_throw_when_timeout_is_less_than_execution_duration__optimisti var policy = Policy.Timeout(TimeSpan.FromMilliseconds(50), TimeoutStrategy.Optimistic); var userCancellationToken = CancellationToken.None; - policy.Invoking(p => p.Execute(ct => SystemClock.Sleep(TimeSpan.FromSeconds(3), ct), userCancellationToken)) // Delegate observes cancellation token, so permitting optimistic cancellation. + policy.Invoking(p => p.Execute(ct => SystemClock.Sleep(TimeSpan.FromSeconds(3), ct), userCancellationToken)) // Delegate observes cancellation token, so permitting optimistic cancellation. .Should().Throw(); } @@ -397,7 +397,7 @@ public void Should_throw_timeout_after_correct_duration__optimistic() TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. watch.Start(); - policy.Invoking(p => p.Execute(ct => SystemClock.Sleep(TimeSpan.FromSeconds(10), ct), userCancellationToken)) // Delegate observes cancellation token, so permitting optimistic cancellation. + policy.Invoking(p => p.Execute(ct => SystemClock.Sleep(TimeSpan.FromSeconds(10), ct), userCancellationToken)) // Delegate observes cancellation token, so permitting optimistic cancellation. .Should().Throw(); watch.Stop(); @@ -626,7 +626,7 @@ public void Should_call_ontimeout_with_task_wrapping_abandoned_action__pessimist [Fact] public void Should_call_ontimeout_with_task_wrapping_abandoned_action_allowing_capture_of_otherwise_unobserved_exception__pessimistic() { - SystemClock.Reset(); // This is the only test which cannot work with the artificial SystemClock of TimeoutSpecsBase. We want the invoked delegate to continue as far as: throw exceptionToThrow, to genuinely check that the walked-away-from task throws that, and that we pass it to onTimeout. + SystemClock.Reset(); // This is the only test which cannot work with the artificial SystemClock of TimeoutSpecsBase. We want the invoked delegate to continue as far as: throw exceptionToThrow, to genuinely check that the walked-away-from task throws that, and that we pass it to onTimeout. // That means we can't use the SystemClock.Sleep(...) within the executed delegate to artificially trigger the timeout cancellation (as for example the test above does). // In real execution, it is the .Wait(timeoutCancellationTokenSource.Token) in the timeout implementation which throws for the timeout. We don't want to go as far as abstracting Task.Wait() out into SystemClock, so we let this test run at real-world speed, not abstracted-clock speed. diff --git a/src/Polly.Specs/Timeout/TimeoutSpecsBase.cs b/src/Polly.Specs/Timeout/TimeoutSpecsBase.cs index e5deefbea6e..ab41228407f 100644 --- a/src/Polly.Specs/Timeout/TimeoutSpecsBase.cs +++ b/src/Polly.Specs/Timeout/TimeoutSpecsBase.cs @@ -22,7 +22,7 @@ public abstract class TimeoutSpecsBase : IDisposable private DateTimeOffset _offsetUtcNow = DateTimeOffset.UtcNow; private DateTime _utcNow = DateTime.UtcNow; - + protected TimeoutSpecsBase() { // Override the SystemClock, to return time stored in variables we manipulate. @@ -94,7 +94,7 @@ public void Dispose() /// A helper method which simply throws the passed exception. Supports tests verifying the stack trace of where an exception was thrown, by throwing that exception from a specific (other) location. /// /// The exception to throw. - [MethodImpl(MethodImplOptions.NoInlining)] // Tests that use this method assert that the exception was thrown from within this method; therefore, it is essential that + [MethodImpl(MethodImplOptions.NoInlining)] // Tests that use this method assert that the exception was thrown from within this method; therefore, it is essential that protected void Helper_ThrowException(Exception ex) { throw ex; diff --git a/src/Polly.Specs/Wrap/IPolicyWrapExtensionSpecs.cs b/src/Polly.Specs/Wrap/IPolicyWrapExtensionSpecs.cs index 8f18318b9a7..7c0c019ff05 100644 --- a/src/Polly.Specs/Wrap/IPolicyWrapExtensionSpecs.cs +++ b/src/Polly.Specs/Wrap/IPolicyWrapExtensionSpecs.cs @@ -182,7 +182,7 @@ public void GetPoliciesTPolicy_with_predicate_should_throw_if_predicate_is_null( PolicyWrap wrap = policyA.Wrap(policyB); Action configure = () => wrap.GetPolicies(null); - + configure.Should().Throw().And.ParamName.Should().Be("filter"); } diff --git a/src/Polly/AsyncPolicy.cs b/src/Polly/AsyncPolicy.cs index a1c2b7df9c7..50d5b910ae3 100644 --- a/src/Polly/AsyncPolicy.cs +++ b/src/Polly/AsyncPolicy.cs @@ -6,7 +6,7 @@ public abstract partial class AsyncPolicy { /// - /// Constructs a new instance of a derived type with the passed . + /// Constructs a new instance of a derived type with the passed . /// /// Predicates indicating which exceptions the policy should handle. internal AsyncPolicy(ExceptionPredicates exceptionPredicates) @@ -15,7 +15,7 @@ internal AsyncPolicy(ExceptionPredicates exceptionPredicates) } /// - /// Constructs a new instance of a derived type with the passed . + /// Constructs a new instance of a derived type with the passed . /// /// A specifying which exceptions the policy should handle. protected AsyncPolicy(PolicyBuilder policyBuilder = null) diff --git a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs index e3c3a8f6ec3..792e5fd3b75 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs @@ -12,7 +12,7 @@ internal static async Task ImplementationAsync( Func onBulkheadRejectedAsync, SemaphoreSlim maxParallelizationSemaphore, SemaphoreSlim maxQueuedActionsSemaphore, - CancellationToken cancellationToken, + CancellationToken cancellationToken, bool continueOnCapturedContext) { if (!await maxQueuedActionsSemaphore.WaitAsync(TimeSpan.Zero, cancellationToken).ConfigureAwait(continueOnCapturedContext)) @@ -24,7 +24,7 @@ internal static async Task ImplementationAsync( { await maxParallelizationSemaphore.WaitAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext); - try + try { return await action(context, cancellationToken).ConfigureAwait(continueOnCapturedContext); } diff --git a/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs b/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs index 44a93be2557..7ce93513047 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadSyntax.cs @@ -59,8 +59,8 @@ public static AsyncBulkheadPolicy BulkheadAsync(int maxParallelization, int maxQ /// maxQueuingActions;Value must be greater than or equal to zero. /// onBulkheadRejectedAsync public static AsyncBulkheadPolicy BulkheadAsync( - int maxParallelization, - int maxQueuingActions, + int maxParallelization, + int maxQueuingActions, Func onBulkheadRejectedAsync) { if (maxParallelization <= 0) throw new ArgumentOutOfRangeException(nameof(maxParallelization), "Value must be greater than zero."); diff --git a/src/Polly/Bulkhead/BulkheadPolicy.cs b/src/Polly/Bulkhead/BulkheadPolicy.cs index 7f7fa27e610..faa93a6dfa0 100644 --- a/src/Polly/Bulkhead/BulkheadPolicy.cs +++ b/src/Polly/Bulkhead/BulkheadPolicy.cs @@ -41,7 +41,7 @@ protected override TResult Implementation(Func Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); /// - /// Disposes of the , allowing it to dispose its internal resources. + /// Disposes of the , allowing it to dispose its internal resources. /// Only call on a after all actions executed through the policy have completed. If actions are still executing through the policy when is called, an may be thrown on the actions' threads when those actions complete. /// public void Dispose() @@ -89,7 +89,7 @@ protected override TResult Implementation(Func Math.Min(_maxQueuedActionsSemaphore.CurrentCount, _maxQueueingActions); /// - /// Disposes of the , allowing it to dispose its internal resources. + /// Disposes of the , allowing it to dispose its internal resources. /// Only call on a after all actions executed through the policy have completed. If actions are still executing through the policy when is called, an may be thrown on the actions' threads when those actions complete. /// public void Dispose() diff --git a/src/Polly/Bulkhead/BulkheadSyntax.cs b/src/Polly/Bulkhead/BulkheadSyntax.cs index e166f0db2df..535c622d3e0 100644 --- a/src/Polly/Bulkhead/BulkheadSyntax.cs +++ b/src/Polly/Bulkhead/BulkheadSyntax.cs @@ -68,5 +68,5 @@ public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActi onBulkheadRejected ); } - + } diff --git a/src/Polly/Bulkhead/IBulkheadPolicy.cs b/src/Polly/Bulkhead/IBulkheadPolicy.cs index 7a48a593b6e..61aeec43300 100644 --- a/src/Polly/Bulkhead/IBulkheadPolicy.cs +++ b/src/Polly/Bulkhead/IBulkheadPolicy.cs @@ -24,5 +24,5 @@ public interface IBulkheadPolicy : IsPolicy, IDisposable /// public interface IBulkheadPolicy : IBulkheadPolicy { - + } diff --git a/src/Polly/Caching/AsyncCachePolicy.cs b/src/Polly/Caching/AsyncCachePolicy.cs index e314f98d955..101de13524d 100644 --- a/src/Polly/Caching/AsyncCachePolicy.cs +++ b/src/Polly/Caching/AsyncCachePolicy.cs @@ -8,7 +8,7 @@ namespace Polly.Caching; /// /// A cache policy that can be applied to the results of delegate executions. /// -public class AsyncCachePolicy : AsyncPolicy +public class AsyncCachePolicy : AsyncPolicy { private readonly IAsyncCacheProvider _asyncCacheProvider; private readonly ITtlStrategy _ttlStrategy; @@ -21,7 +21,7 @@ public class AsyncCachePolicy : AsyncPolicy private readonly Action _onCachePutError; internal AsyncCachePolicy( - IAsyncCacheProvider asyncCacheProvider, + IAsyncCacheProvider asyncCacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheGet, @@ -58,16 +58,16 @@ protected override Task ImplementationAsync(Func( - _asyncCacheProvider.AsyncFor(), - _ttlStrategy.For(), - _cacheKeyStrategy, - action, - context, + _asyncCacheProvider.AsyncFor(), + _ttlStrategy.For(), + _cacheKeyStrategy, + action, + context, cancellationToken, - continueOnCapturedContext, - _onCacheGet, - _onCacheMiss, - _onCachePut, + continueOnCapturedContext, + _onCacheGet, + _onCacheMiss, + _onCachePut, _onCacheGetError, _onCachePutError); } diff --git a/src/Polly/Caching/AsyncCacheSyntax.cs b/src/Polly/Caching/AsyncCacheSyntax.cs index 1525083c55e..577b6451206 100644 --- a/src/Polly/Caching/AsyncCacheSyntax.cs +++ b/src/Polly/Caching/AsyncCacheSyntax.cs @@ -202,8 +202,8 @@ public static AsyncCachePolicy CacheAsync( /// onCacheGetError /// onCachePutError public static AsyncCachePolicy CacheAsync( - IAsyncCacheProvider cacheProvider, - TimeSpan ttl, + IAsyncCacheProvider cacheProvider, + TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheGet, Action onCacheMiss, diff --git a/src/Polly/Caching/CachePolicy.cs b/src/Polly/Caching/CachePolicy.cs index f6a82a2e2ad..7ba908b549d 100644 --- a/src/Polly/Caching/CachePolicy.cs +++ b/src/Polly/Caching/CachePolicy.cs @@ -20,7 +20,7 @@ public class CachePolicy : Policy, ICachePolicy private readonly Action _onCachePutError; internal CachePolicy( - ISyncCacheProvider syncCacheProvider, + ISyncCacheProvider syncCacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheGet, diff --git a/src/Polly/Caching/CacheSyntax.cs b/src/Polly/Caching/CacheSyntax.cs index a669b1e35b4..6331e6113b3 100644 --- a/src/Polly/Caching/CacheSyntax.cs +++ b/src/Polly/Caching/CacheSyntax.cs @@ -208,8 +208,8 @@ public static CachePolicy Cache( /// onCacheGetError /// onCachePutError public static CachePolicy Cache( - ISyncCacheProvider cacheProvider, - TimeSpan ttl, + ISyncCacheProvider cacheProvider, + TimeSpan ttl, ICacheKeyStrategy cacheKeyStrategy, Action onCacheGet, Action onCacheMiss, @@ -280,7 +280,7 @@ public static CachePolicy Cache( /// onCachePutError public static CachePolicy Cache( ISyncCacheProvider cacheProvider, - TimeSpan ttl, + TimeSpan ttl, Func cacheKeyStrategy, Action onCacheGet, Action onCacheMiss, @@ -315,13 +315,13 @@ public static CachePolicy Cache( /// onCacheGetError /// onCachePutError public static CachePolicy Cache( - ISyncCacheProvider cacheProvider, + ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheGet, Action onCacheMiss, Action onCachePut, - Action onCacheGetError, + Action onCacheGetError, Action onCachePutError) { if (cacheProvider == null) throw new ArgumentNullException(nameof(cacheProvider)); diff --git a/src/Polly/Caching/CacheTResultSyntax.cs b/src/Polly/Caching/CacheTResultSyntax.cs index fe09af2fea1..d80e4a03d5b 100644 --- a/src/Polly/Caching/CacheTResultSyntax.cs +++ b/src/Polly/Caching/CacheTResultSyntax.cs @@ -330,7 +330,7 @@ public static CachePolicy Cache( /// onCachePutError public static CachePolicy Cache( ISyncCacheProvider cacheProvider, - ITtlStrategy ttlStrategy, + ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Action onCacheGet, Action onCacheMiss, diff --git a/src/Polly/Caching/ITtlStrategy.cs b/src/Polly/Caching/ITtlStrategy.cs index f4cf30357f1..9c13a6e5cef 100644 --- a/src/Polly/Caching/ITtlStrategy.cs +++ b/src/Polly/Caching/ITtlStrategy.cs @@ -5,7 +5,7 @@ /// public interface ITtlStrategy : ITtlStrategy { - + } /// diff --git a/src/Polly/Caching/Ttl.cs b/src/Polly/Caching/Ttl.cs index 7dd10fcbf87..49c393ce826 100644 --- a/src/Polly/Caching/Ttl.cs +++ b/src/Polly/Caching/Ttl.cs @@ -20,7 +20,7 @@ public struct Ttl /// /// Creates a new struct. /// - /// The timespan for which this cache-item remains valid. + /// The timespan for which this cache-item remains valid. /// Will be considered as not denoting sliding expiration. public Ttl(TimeSpan timeSpan) : this(timeSpan, false) { diff --git a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs index 869f6d6a3ae..ccb172930fe 100644 --- a/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AdvancedCircuitBreakerTResultSyntax.cs @@ -5,7 +5,7 @@ namespace Polly; /// -/// Fluent API for defining a Circuit Breaker . +/// Fluent API for defining a Circuit Breaker . /// public static class AdvancedCircuitBreakerTResultSyntax { diff --git a/src/Polly/CircuitBreaker/AdvancedCircuitController.cs b/src/Polly/CircuitBreaker/AdvancedCircuitController.cs index e40bf28f3df..778f5e0a461 100644 --- a/src/Polly/CircuitBreaker/AdvancedCircuitController.cs +++ b/src/Polly/CircuitBreaker/AdvancedCircuitController.cs @@ -13,12 +13,12 @@ internal class AdvancedCircuitController : CircuitStateController, CircuitState, TimeSpan, Context> onBreak, - Action onReset, + double failureThreshold, + TimeSpan samplingDuration, + int minimumThroughput, + TimeSpan durationOfBreak, + Action, CircuitState, TimeSpan, Context> onBreak, + Action onReset, Action onHalfOpen ) : base(durationOfBreak, onBreak, onReset, onHalfOpen) { diff --git a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs index d654a29b231..e688d341c53 100644 --- a/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncAdvancedCircuitBreakerTResultSyntax.cs @@ -5,7 +5,7 @@ namespace Polly; /// -/// Fluent API for defining a Circuit Breaker . +/// Fluent API for defining a Circuit Breaker . /// public static class AsyncAdvancedCircuitBreakerTResultSyntax { diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs index fb27f91880e..cfc8290b681 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs @@ -8,11 +8,11 @@ namespace Polly.CircuitBreaker; internal class AsyncCircuitBreakerEngine { internal static async Task ImplementationAsync( - Func> action, + Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext, - ExceptionPredicates shouldHandleExceptionPredicates, + ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, ICircuitController breakerController) { diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs index ec179516f23..ac958850da9 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs @@ -14,7 +14,7 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuitBreakerPolicy internal readonly ICircuitController _breakerController; internal AsyncCircuitBreakerPolicy( - PolicyBuilder policyBuilder, + PolicyBuilder policyBuilder, ICircuitController breakerController ) : base(policyBuilder) { @@ -68,7 +68,7 @@ public class AsyncCircuitBreakerPolicy : AsyncPolicy, ICircuit internal readonly ICircuitController _breakerController; internal AsyncCircuitBreakerPolicy( - PolicyBuilder policyBuilder, + PolicyBuilder policyBuilder, ICircuitController breakerController ) : base(policyBuilder) { diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs index 2d092ea7bfd..cd2f10d222f 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerSyntax.cs @@ -5,7 +5,7 @@ namespace Polly; /// -/// Fluent API for defining a Circuit Breaker . +/// Fluent API for defining a Circuit Breaker . /// public static class AsyncCircuitBreakerSyntax { @@ -14,7 +14,7 @@ public static class AsyncCircuitBreakerSyntax /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break @@ -45,7 +45,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break @@ -75,7 +75,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break @@ -96,9 +96,9 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p { Action doNothingOnHalfOpen = () => { }; return policyBuilder.CircuitBreakerAsync( - exceptionsAllowedBeforeBreaking, - durationOfBreak, - onBreak, + exceptionsAllowedBeforeBreaking, + durationOfBreak, + onBreak, onReset, doNothingOnHalfOpen ); @@ -109,7 +109,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break @@ -141,7 +141,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break @@ -174,7 +174,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(this PolicyBuilder p /// The circuit will break if /// exceptions that are handled by this policy are raised consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception + /// while the circuit is broken, will immediately throw a containing the exception /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception, the circuit will break diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs index a25361f3ff3..a02f185c2b4 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerTResultSyntax.cs @@ -4,7 +4,7 @@ namespace Polly; /// -/// Fluent API for defining a Circuit Breaker . +/// Fluent API for defining a Circuit Breaker . /// public static class AsyncCircuitBreakerTResultSyntax { @@ -13,7 +13,7 @@ public static class AsyncCircuitBreakerTResultSyntax /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -44,7 +44,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -74,7 +74,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -95,9 +95,9 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th { Action doNothingOnHalfOpen = () => { }; return policyBuilder.CircuitBreakerAsync( - handledEventsAllowedBeforeBreaking, - durationOfBreak, - onBreak, + handledEventsAllowedBeforeBreaking, + durationOfBreak, + onBreak, onReset, doNothingOnHalfOpen ); @@ -108,7 +108,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -140,7 +140,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -173,7 +173,7 @@ public static AsyncCircuitBreakerPolicy CircuitBreakerAsync(th /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break diff --git a/src/Polly/CircuitBreaker/BrokenCircuitException.cs b/src/Polly/CircuitBreaker/BrokenCircuitException.cs index 61974b58f8d..cf379641d9c 100644 --- a/src/Polly/CircuitBreaker/BrokenCircuitException.cs +++ b/src/Polly/CircuitBreaker/BrokenCircuitException.cs @@ -81,7 +81,7 @@ public BrokenCircuitException(string message, TResult result) : base(message) /// /// The result value which was considered a handled fault, by the policy. /// - public TResult Result { get => result; } + public TResult Result { get => result; } #if NETSTANDARD2_0 /// diff --git a/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs b/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs index ad34434ee78..773615b520b 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerEngine.cs @@ -10,8 +10,8 @@ internal static TResult Implementation( Func action, Context context, CancellationToken cancellationToken, - ExceptionPredicates shouldHandleExceptionPredicates, - ResultPredicates shouldHandleResultPredicates, + ExceptionPredicates shouldHandleExceptionPredicates, + ResultPredicates shouldHandleResultPredicates, ICircuitController breakerController) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs index af202e9663a..0dee7c425b1 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs @@ -63,7 +63,7 @@ public class CircuitBreakerPolicy : Policy, ICircuitBreakerPol internal readonly ICircuitController _breakerController; internal CircuitBreakerPolicy( - PolicyBuilder policyBuilder, + PolicyBuilder policyBuilder, ICircuitController breakerController ) : base(policyBuilder) => _breakerController = breakerController; diff --git a/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs b/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs index 524c1f22222..300a1b486b5 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerTResultSyntax.cs @@ -4,7 +4,7 @@ namespace Polly; /// -/// Fluent API for defining a Circuit Breaker . +/// Fluent API for defining a Circuit Breaker . /// public static class CircuitBreakerTResultSyntax { @@ -13,7 +13,7 @@ public static class CircuitBreakerTResultSyntax /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -46,7 +46,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -76,7 +76,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -109,7 +109,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -141,7 +141,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break @@ -174,7 +174,7 @@ public static CircuitBreakerPolicy CircuitBreaker(this PolicyB /// The circuit will break if /// exceptions or results that are handled by this policy are encountered consecutively. /// The circuit will stay broken for the . Any attempt to execute this policy - /// while the circuit is broken, will immediately throw a containing the exception or result + /// while the circuit is broken, will immediately throw a containing the exception or result /// that broke the circuit. /// /// If the first action after the break duration period results in a handled exception or result, the circuit will break diff --git a/src/Polly/CircuitBreaker/CircuitStateController.cs b/src/Polly/CircuitBreaker/CircuitStateController.cs index 8a6b148299f..f7073c08b7f 100644 --- a/src/Polly/CircuitBreaker/CircuitStateController.cs +++ b/src/Polly/CircuitBreaker/CircuitStateController.cs @@ -18,9 +18,9 @@ internal abstract class CircuitStateController : ICircuitController, CircuitState, TimeSpan, Context> onBreak, - Action onReset, + TimeSpan durationOfBreak, + Action, CircuitState, TimeSpan, Context> onBreak, + Action onReset, Action onHalfOpen) { _durationOfBreak = durationOfBreak; @@ -70,7 +70,7 @@ public TResult LastHandledResult { using (TimedLock.Lock(_lock)) { - return _lastOutcome != null + return _lastOutcome != null ? _lastOutcome.Result : default; } } diff --git a/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs b/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs index ee93a6ef664..562288d21d3 100644 --- a/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs +++ b/src/Polly/CircuitBreaker/ConsecutiveCountCircuitController.cs @@ -9,10 +9,10 @@ internal class ConsecutiveCountCircuitController : CircuitStateControll private int _consecutiveFailureCount; public ConsecutiveCountCircuitController( - int exceptionsAllowedBeforeBreaking, - TimeSpan durationOfBreak, - Action, CircuitState, TimeSpan, Context> onBreak, - Action onReset, + int exceptionsAllowedBeforeBreaking, + TimeSpan durationOfBreak, + Action, CircuitState, TimeSpan, Context> onBreak, + Action onReset, Action onHalfOpen ) : base(durationOfBreak, onBreak, onReset, onHalfOpen) { diff --git a/src/Polly/Context.Dictionary.cs b/src/Polly/Context.Dictionary.cs index 60c35e4a7fc..6dd027fb02e 100644 --- a/src/Polly/Context.Dictionary.cs +++ b/src/Polly/Context.Dictionary.cs @@ -10,7 +10,7 @@ namespace Polly; /// public partial class Context : IDictionary, IDictionary, IReadOnlyDictionary { - // For an individual execution through a policy or policywrap, it is expected that all execution steps (for example executing the user delegate, invoking policy-activity delegates such as onRetry, onBreak, onTimeout etc) execute sequentially. + // For an individual execution through a policy or policywrap, it is expected that all execution steps (for example executing the user delegate, invoking policy-activity delegates such as onRetry, onBreak, onTimeout etc) execute sequentially. // Therefore, this class is intentionally not constructed to be safe for concurrent access from multiple threads. private Dictionary wrappedDictionary; @@ -87,22 +87,22 @@ public void Add(string key, object value) /// public IEnumerator> GetEnumerator() => WrappedDictionary.GetEnumerator(); - /// + /// IEnumerator IEnumerable.GetEnumerator() => WrappedDictionary.GetEnumerator(); - /// + /// public void Add(object key, object value) => ((IDictionary)WrappedDictionary).Add(key, value); - /// + /// public bool Contains(object key) => ((IDictionary)WrappedDictionary).Contains(key); - /// + /// IDictionaryEnumerator IDictionary.GetEnumerator() => ((IDictionary)WrappedDictionary).GetEnumerator(); - /// + /// public void Remove(object key) => ((IDictionary)WrappedDictionary).Remove(key); - /// + /// public void CopyTo(Array array, int index) => ((IDictionary)WrappedDictionary).CopyTo(array, index); #endregion @@ -115,23 +115,23 @@ public void Add(string key, object value) #region IDictionary implementation - /// + /// bool IDictionary.IsFixedSize => ((IDictionary)WrappedDictionary).IsFixedSize; - /// + /// bool IDictionary.IsReadOnly => ((IDictionary)WrappedDictionary).IsReadOnly; ICollection IDictionary.Keys => ((IDictionary)WrappedDictionary).Keys; ICollection IDictionary.Values => ((IDictionary)WrappedDictionary).Values; - /// + /// bool ICollection.IsSynchronized => ((IDictionary)WrappedDictionary).IsSynchronized; - /// + /// object ICollection.SyncRoot => ((IDictionary)WrappedDictionary).SyncRoot; - /// + /// object IDictionary.this[object key] { get => ((IDictionary)WrappedDictionary)[key]; set => ((IDictionary)WrappedDictionary)[key] = value; } #endregion diff --git a/src/Polly/ExceptionPredicate.cs b/src/Polly/ExceptionPredicate.cs index 810e98440d0..da5c263db43 100644 --- a/src/Polly/ExceptionPredicate.cs +++ b/src/Polly/ExceptionPredicate.cs @@ -3,7 +3,7 @@ namespace Polly; /// -/// A predicate that can be run against a passed . +/// A predicate that can be run against a passed . /// /// The passed exception, against which to evaluate the predicate. /// A matched ; or null, if an exception was not matched. ExceptionPredicate implementations may return the passed Exception , indicating that it matched the predicate. They may also return inner exceptions of the passed Exception , to indicate that the returned inner exception matched the predicate. diff --git a/src/Polly/ExecutionRejectedException.cs b/src/Polly/ExecutionRejectedException.cs index 0d9c0dd37e8..dec2b0af7ed 100644 --- a/src/Polly/ExecutionRejectedException.cs +++ b/src/Polly/ExecutionRejectedException.cs @@ -6,7 +6,7 @@ namespace Polly; /// -/// Exception thrown when a policy rejects execution of a delegate. +/// Exception thrown when a policy rejects execution of a delegate. /// More specific exceptions which derive from this type, are generally thrown. /// public abstract class ExecutionRejectedException : Exception diff --git a/src/Polly/Fallback/AsyncFallbackPolicy.cs b/src/Polly/Fallback/AsyncFallbackPolicy.cs index 974cddba326..00c8bd06a35 100644 --- a/src/Polly/Fallback/AsyncFallbackPolicy.cs +++ b/src/Polly/Fallback/AsyncFallbackPolicy.cs @@ -47,7 +47,7 @@ protected override Task ImplementationAsync( /// protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) - => + => throw new InvalidOperationException($"You have executed the generic .Execute<{nameof(TResult)}> method on a non-generic {nameof(FallbackPolicy)}. A non-generic {nameof(FallbackPolicy)} only defines a fallback action which returns void; it can never return a substitute {nameof(TResult)} value. To use {nameof(FallbackPolicy)} to provide fallback {nameof(TResult)} values you must define a generic fallback policy {nameof(FallbackPolicy)}<{nameof(TResult)}>. For example, define the policy as Policy<{nameof(TResult)}>.Handle.Fallback<{nameof(TResult)}>(/* some {nameof(TResult)} value or Func<..., {nameof(TResult)}> */);"); } @@ -62,7 +62,7 @@ public class AsyncFallbackPolicy : AsyncPolicy, IFallbackPolic internal AsyncFallbackPolicy( PolicyBuilder policyBuilder, - Func, Context, Task> onFallbackAsync, + Func, Context, Task> onFallbackAsync, Func, Context, CancellationToken, Task> fallbackAction ) : base(policyBuilder) { diff --git a/src/Polly/Fallback/FallbackPolicy.cs b/src/Polly/Fallback/FallbackPolicy.cs index 8933a8c6366..c0035d46152 100644 --- a/src/Polly/Fallback/FallbackPolicy.cs +++ b/src/Polly/Fallback/FallbackPolicy.cs @@ -27,9 +27,9 @@ internal FallbackPolicy( [DebuggerStepThrough] protected override void Implementation(Action action, Context context, CancellationToken cancellationToken) => FallbackEngine.Implementation( - (ctx, token) => { action(ctx, token); return EmptyStruct.Instance; }, - context, - cancellationToken, + (ctx, token) => { action(ctx, token); return EmptyStruct.Instance; }, + context, + cancellationToken, ExceptionPredicates, ResultPredicates.None, (outcome, ctx) => _onFallback(outcome.Exception, ctx), diff --git a/src/Polly/IsPolicy.cs b/src/Polly/IsPolicy.cs index 559d815e1a9..5ba8583d449 100644 --- a/src/Polly/IsPolicy.cs +++ b/src/Polly/IsPolicy.cs @@ -4,7 +4,7 @@ /// A marker interface identifying Polly policies of all types, and containing properties common to all policies /// public interface IsPolicy -{ +{ /// /// A key intended to be unique to each policy instance, which is passed with executions as the property. /// diff --git a/src/Polly/NoOp/AsyncNoOpPolicy.cs b/src/Polly/NoOp/AsyncNoOpPolicy.cs index 39dbc67b577..ea04eca0e68 100644 --- a/src/Polly/NoOp/AsyncNoOpPolicy.cs +++ b/src/Polly/NoOp/AsyncNoOpPolicy.cs @@ -10,7 +10,7 @@ namespace Polly.NoOp; /// public class AsyncNoOpPolicy : AsyncPolicy, INoOpPolicy { - internal AsyncNoOpPolicy() + internal AsyncNoOpPolicy() { } @@ -26,7 +26,7 @@ protected override Task ImplementationAsync( Func public class AsyncNoOpPolicy : AsyncPolicy, INoOpPolicy { - internal AsyncNoOpPolicy() + internal AsyncNoOpPolicy() { } diff --git a/src/Polly/Policy.HandleSyntax.cs b/src/Polly/Policy.HandleSyntax.cs index 0314e9bb291..a7879bd5b8f 100644 --- a/src/Polly/Policy.HandleSyntax.cs +++ b/src/Polly/Policy.HandleSyntax.cs @@ -54,7 +54,7 @@ public static PolicyBuilder HandleResult(Func r /// The TResult value this policy will handle. /// This policy filter matches the value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate. /// The PolicyBuilder instance. - public static PolicyBuilder HandleResult(TResult result) + public static PolicyBuilder HandleResult(TResult result) => HandleResult(new Func(r => (r != null && r.Equals(result)) || (r == null && result == null))); } diff --git a/src/Polly/Policy.cs b/src/Polly/Policy.cs index 192d7d8c2e0..448defb34c1 100644 --- a/src/Polly/Policy.cs +++ b/src/Polly/Policy.cs @@ -6,7 +6,7 @@ public abstract partial class Policy : PolicyBase { /// - /// Constructs a new instance of a derived type with the passed . + /// Constructs a new instance of a derived type with the passed . /// /// Predicates indicating which exceptions the policy should handle. internal Policy(ExceptionPredicates exceptionPredicates) @@ -15,7 +15,7 @@ internal Policy(ExceptionPredicates exceptionPredicates) } /// - /// Constructs a new instance of a derived type with the passed . + /// Constructs a new instance of a derived type with the passed . /// /// A specifying which exceptions the policy should handle. protected Policy(PolicyBuilder policyBuilder = null) diff --git a/src/Polly/PolicyBuilder.cs b/src/Polly/PolicyBuilder.cs index e4628f043ed..69174532ad1 100644 --- a/src/Polly/PolicyBuilder.cs +++ b/src/Polly/PolicyBuilder.cs @@ -50,7 +50,7 @@ public override bool Equals(object obj) /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() @@ -113,7 +113,7 @@ internal PolicyBuilder(ExceptionPredicates exceptionPredicates) /// A that represents this instance. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override string ToString() => base.ToString(); + public override string ToString() => base.ToString(); /// /// Determines whether the specified is equal to this instance. @@ -129,7 +129,7 @@ internal PolicyBuilder(ExceptionPredicates exceptionPredicates) /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() => base.GetHashCode(); diff --git a/src/Polly/PolicyResult.cs b/src/Polly/PolicyResult.cs index 5452f1f6d80..9af147e8c61 100644 --- a/src/Polly/PolicyResult.cs +++ b/src/Polly/PolicyResult.cs @@ -136,9 +136,9 @@ public static PolicyResult Successful(TResult result, Context context) /// A representing a failed execution through the policy. /// public static PolicyResult Failure(Exception exception, ExceptionType exceptionType, Context context) - => new PolicyResult(default, OutcomeType.Failure, exception, exceptionType, default, - exceptionType == Polly.ExceptionType.HandledByThisPolicy - ? Polly.FaultType.ExceptionHandledByThisPolicy + => new PolicyResult(default, OutcomeType.Failure, exception, exceptionType, default, + exceptionType == Polly.ExceptionType.HandledByThisPolicy + ? Polly.FaultType.ExceptionHandledByThisPolicy : Polly.FaultType.UnhandledException, context); diff --git a/src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs b/src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs index 7120152169f..421dc64800b 100644 --- a/src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs +++ b/src/Polly/RateLimit/LockFreeTokenBucketRateLimiter.cs @@ -75,7 +75,7 @@ public LockFreeTokenBucketRateLimiter(TimeSpan onePer, long bucketCapacity) // And any whole token tick intervals further each merit another. (-ticksTillAddNextToken / addTokenTickInterval); - // We mustn't exceed bucket capacity though. + // We mustn't exceed bucket capacity though. long tokensToAdd = Math.Min(bucketCapacity, tokensMissedAdding); // Work out when tokens would next be due to be added, if we add these tokens. @@ -86,7 +86,7 @@ public LockFreeTokenBucketRateLimiter(TimeSpan onePer, long bucketCapacity) // Now see if we win the race to add these tokens. Other threads might be racing through this code at the same time: only one thread must add the tokens! if (Interlocked.CompareExchange(ref addNextTokenAtTicks, newAddNextTokenAtTicks, currentAddNextTokenAtTicks) == currentAddNextTokenAtTicks) { - // We won the race to add the tokens! + // We won the race to add the tokens! // Theoretically we want to add tokensToAdd tokens. But in fact we don't do that. // We want to claim one of those tokens for ourselves - there's no way we're going to add it but let another thread snatch it from under our nose. @@ -94,9 +94,9 @@ public LockFreeTokenBucketRateLimiter(TimeSpan onePer, long bucketCapacity) // So in fact we add (tokensToAdd - 1) tokens (ie we consume one), and return, permitting this execution. - // The advantage of only adding tokens when the bucket is empty is that we can now hard set the new amount of tokens (Interlocked.Exchange) without caring if other threads have simultaneously been taking or adding tokens. + // The advantage of only adding tokens when the bucket is empty is that we can now hard set the new amount of tokens (Interlocked.Exchange) without caring if other threads have simultaneously been taking or adding tokens. // (If we added a token per addTokenTickInterval to a non-empty bucket, the reasoning about not overflowing the bucket seems harder.) - Interlocked.Exchange(ref currentTokens, tokensToAdd - 1); + Interlocked.Exchange(ref currentTokens, tokensToAdd - 1); return (true, TimeSpan.Zero); } else diff --git a/src/Polly/Registry/IConcurrentPolicyRegistry.cs b/src/Polly/Registry/IConcurrentPolicyRegistry.cs index 903eeee870d..8b5a2a3dc8d 100644 --- a/src/Polly/Registry/IConcurrentPolicyRegistry.cs +++ b/src/Polly/Registry/IConcurrentPolicyRegistry.cs @@ -57,33 +57,33 @@ public interface IConcurrentPolicyRegistry : IPolicyRegistry /// /// The key of the policy to add. /// the value to be added, if the key does not already exist - /// The policy for the key. This will be either the existing policy for the key if the + /// The policy for the key. This will be either the existing policy for the key if the /// key is already in the registry, or the new policy if the key was not in the registry. TPolicy GetOrAdd(TKey key, TPolicy policy) where TPolicy : IsPolicy; /// - /// Adds a key/policy pair to the registry if the key does not already - /// exist, or updates a key/policy pair in the registry if the key + /// Adds a key/policy pair to the registry if the key does not already + /// exist, or updates a key/policy pair in the registry if the key /// already exists. /// /// The key to be added or whose policy should be updated /// The function used to generate a policy for an absent key /// The function used to generate a new policy for an existing key /// based on the key's existing value - /// The new policy for the key. This will be either be the result of addPolicyFactory (if the key was + /// The new policy for the key. This will be either be the result of addPolicyFactory (if the key was /// absent) or the result of updatePolicyFactory (if the key was present). TPolicy AddOrUpdate(TKey key, Func addPolicyFactory, Func updatePolicyFactory) where TPolicy : IsPolicy; /// - /// Adds a key/policy pair to the registry if the key does not already - /// exist, or updates a key/policy pair in the registry if the key + /// Adds a key/policy pair to the registry if the key does not already + /// exist, or updates a key/policy pair in the registry if the key /// already exists. /// /// The key to be added or whose policy should be updated /// The policy to be added for an absent key - /// The function used to generate a new policy for an existing key based on + /// The function used to generate a new policy for an existing key based on /// the key's existing value - /// The new policy for the key. This will be either be addPolicy (if the key was + /// The new policy for the key. This will be either be addPolicy (if the key was /// absent) or the result of updatePolicyFactory (if the key was present). TPolicy AddOrUpdate(TKey key, TPolicy addPolicy, Func updatePolicyFactory) where TPolicy : IsPolicy; } diff --git a/src/Polly/Registry/PolicyRegistry.cs b/src/Polly/Registry/PolicyRegistry.cs index a2e04bad108..0da0fd538a1 100644 --- a/src/Polly/Registry/PolicyRegistry.cs +++ b/src/Polly/Registry/PolicyRegistry.cs @@ -30,7 +30,7 @@ public PolicyRegistry() /// This internal constructor exists solely to facilitate testing of the GetEnumerator() methods, which allow us to support collection initialisation syntax. /// /// a dictionary containing keys and policies used for testing. - internal PolicyRegistry(IDictionary registry) + internal PolicyRegistry(IDictionary registry) { _registry = registry ?? throw new NullReferenceException(nameof(registry)); } @@ -96,7 +96,7 @@ public IsPolicy this[string key] /// The policy stored in the registry under the given key. /// is null. /// The given key was not present in the registry. - public TPolicy Get(string key) where TPolicy : IsPolicy => + public TPolicy Get(string key) where TPolicy : IsPolicy => (TPolicy) _registry[key]; /// @@ -198,7 +198,7 @@ public TPolicy GetOrAdd(string key, Func policyFactory /// /// The key of the policy to add. /// the policy to be added, if the key does not already exist - /// The policy for the key. This will be either the existing policy for the key if the + /// The policy for the key. This will be either the existing policy for the key if the /// key is already in the registry, or the new policy if the key was not in the registry. public TPolicy GetOrAdd(string key, TPolicy policy) where TPolicy : IsPolicy { @@ -208,15 +208,15 @@ public TPolicy GetOrAdd(string key, TPolicy policy) where TPolicy : IsP } /// - /// Adds a key/policy pair to the registry if the key does not already - /// exist, or updates a key/policy pair in the registry if the key + /// Adds a key/policy pair to the registry if the key does not already + /// exist, or updates a key/policy pair in the registry if the key /// already exists. /// /// The key to be added or whose policy should be updated /// The function used to generate a policy for an absent key /// The function used to generate a new policy for an existing key /// based on the key's existing value - /// The new policy for the key. This will be either be the result of addPolicyFactory (if the key was + /// The new policy for the key. This will be either be the result of addPolicyFactory (if the key was /// absent) or the result of updatePolicyFactory (if the key was present). public TPolicy AddOrUpdate(string key, Func addPolicyFactory, Func updatePolicyFactory) where TPolicy : IsPolicy { @@ -226,15 +226,15 @@ public TPolicy AddOrUpdate(string key, Func addPolicyF } /// - /// Adds a key/policy pair to the registry if the key does not already - /// exist, or updates a key/policy pair in the registry if the key + /// Adds a key/policy pair to the registry if the key does not already + /// exist, or updates a key/policy pair in the registry if the key /// already exists. /// /// The key to be added or whose policy should be updated /// The policy to be added for an absent key - /// The function used to generate a new policy for an existing key based on + /// The function used to generate a new policy for an existing key based on /// the key's existing value - /// The new policy for the key. This will be either be addPolicy (if the key was + /// The new policy for the key. This will be either be addPolicy (if the key was /// absent) or the result of updatePolicyFactory (if the key was present). public TPolicy AddOrUpdate(string key, TPolicy addPolicy, Func updatePolicyFactory) where TPolicy : IsPolicy { @@ -251,7 +251,7 @@ public TPolicy AddOrUpdate(string key, TPolicy addPolicy, Func was called. - /// This is not considered a significant issue as typical usage of PolicyRegistry is for bulk population at app startup, + /// This is not considered a significant issue as typical usage of PolicyRegistry is for bulk population at app startup, /// with only infrequent changes to the PolicyRegistry during app running, if using PolicyRegistry for dynamic updates during running. /// public IEnumerator> GetEnumerator() => _registry.GetEnumerator(); @@ -264,7 +264,7 @@ public TPolicy AddOrUpdate(string key, TPolicy addPolicy, Func was called. - /// This is not considered a significant issue as typical usage of PolicyRegistry is for bulk population at app startup, + /// This is not considered a significant issue as typical usage of PolicyRegistry is for bulk population at app startup, /// with only infrequent changes to the PolicyRegistry during app running, if using PolicyRegistry for dynamic updates during running. /// IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); diff --git a/src/Polly/Retry/AsyncRetryPolicy.cs b/src/Polly/Retry/AsyncRetryPolicy.cs index 933dc2dd78d..13dc5431db5 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -45,8 +45,8 @@ protected override Task ImplementationAsync(Func _onRetryAsync(outcome.Exception, timespan, retryCount, ctx), _permittedRetryCount, _sleepDurationsEnumerable, - _sleepDurationProvider != null - ? (retryCount, outcome, ctx) => _sleepDurationProvider(retryCount, outcome.Exception, ctx) + _sleepDurationProvider != null + ? (retryCount, outcome, ctx) => _sleepDurationProvider(retryCount, outcome.Exception, ctx) : (Func, Context, TimeSpan>)null, continueOnCapturedContext ); diff --git a/src/Polly/Retry/RetryEngine.cs b/src/Polly/Retry/RetryEngine.cs index 80b9873208e..db9b90237cd 100644 --- a/src/Polly/Retry/RetryEngine.cs +++ b/src/Polly/Retry/RetryEngine.cs @@ -40,7 +40,7 @@ internal static TResult Implementation( } canRetry = tryCount < permittedRetryCount && (sleepDurationsEnumerator == null || sleepDurationsEnumerator.MoveNext()); - + if (!canRetry) { return result; @@ -70,7 +70,7 @@ internal static TResult Implementation( if (tryCount < int.MaxValue) { tryCount++; } TimeSpan waitDuration = sleepDurationsEnumerator?.Current ?? (sleepDurationProvider?.Invoke(tryCount, outcome, context) ?? TimeSpan.Zero); - + onRetry(outcome, waitDuration, tryCount, context); if (waitDuration > TimeSpan.Zero) diff --git a/src/Polly/Retry/RetryPolicy.cs b/src/Polly/Retry/RetryPolicy.cs index 7ae2f297117..3efe0d1f99a 100644 --- a/src/Polly/Retry/RetryPolicy.cs +++ b/src/Polly/Retry/RetryPolicy.cs @@ -17,11 +17,11 @@ public class RetryPolicy : Policy, IRetryPolicy internal RetryPolicy( PolicyBuilder policyBuilder, - Action onRetry, + Action onRetry, int permittedRetryCount = Int32.MaxValue, IEnumerable sleepDurationsEnumerable = null, Func sleepDurationProvider = null - ) + ) : base(policyBuilder) { _permittedRetryCount = permittedRetryCount; @@ -33,11 +33,11 @@ internal RetryPolicy( /// protected override TResult Implementation(Func action, Context context, CancellationToken cancellationToken) => RetryEngine.Implementation( - action, - context, + action, + context, cancellationToken, ExceptionPredicates, - ResultPredicates.None, + ResultPredicates.None, (outcome, timespan, retryCount, ctx) => _onRetry(outcome.Exception, timespan, retryCount, ctx), _permittedRetryCount, _sleepDurationsEnumerable, @@ -83,7 +83,7 @@ protected override TResult Implementation(Func ImplementationAsync( - Func> action, - Context context, - CancellationToken cancellationToken, + Func> action, + Context context, + CancellationToken cancellationToken, Func timeoutProvider, TimeoutStrategy timeoutStrategy, - Func onTimeoutAsync, + Func onTimeoutAsync, bool continueOnCapturedContext) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/Timeout/AsyncTimeoutPolicy.cs b/src/Polly/Timeout/AsyncTimeoutPolicy.cs index 2f54da39504..b298195d79b 100644 --- a/src/Polly/Timeout/AsyncTimeoutPolicy.cs +++ b/src/Polly/Timeout/AsyncTimeoutPolicy.cs @@ -28,8 +28,8 @@ Func onTimeoutAsync /// [DebuggerStepThrough] protected override Task ImplementationAsync( - Func> action, - Context context, + Func> action, + Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) { @@ -39,7 +39,7 @@ protected override Task ImplementationAsync( cancellationToken, _timeoutProvider, _timeoutStrategy, - _onTimeoutAsync, + _onTimeoutAsync, continueOnCapturedContext); } } @@ -67,8 +67,8 @@ internal AsyncTimeoutPolicy( /// [DebuggerStepThrough] protected override Task ImplementationAsync( - Func> action, - Context context, + Func> action, + Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => AsyncTimeoutEngine.ImplementationAsync( diff --git a/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs b/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs index 0caf403a8bd..7b46b803ff9 100644 --- a/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs +++ b/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs @@ -39,7 +39,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(int seconds, Tim /// Builds an that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// The number of seconds after which to timeout. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// seconds;Value must be greater than zero. @@ -72,7 +72,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(int seconds, Fun /// /// The number of seconds after which to timeout. /// The timeout strategy. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// seconds;Value must be greater than zero. @@ -134,7 +134,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(TimeSpan timeout /// Builds an that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// The timeout. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeout;Value must be a positive TimeSpan (or Timeout.InfiniteTimeSpan to indicate no timeout) @@ -168,7 +168,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(TimeSpan timeout /// Builds an that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// The timeout. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The timeout strategy. /// The policy instance. @@ -231,7 +231,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func t /// Builds an that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// A function to provide the timeout for this execution. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeoutProvider @@ -264,7 +264,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func t /// /// A function to provide the timeout for this execution. /// The timeout strategy. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeoutProvider @@ -322,7 +322,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// A function to provide the timeout for this execution. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeoutProvider @@ -334,7 +334,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func that will wait asynchronously for a delegate to complete for a specified period of time. A will be thrown if the delegate does not complete within the configured timeout. /// /// A function to provide the timeout for this execution. - /// An action to call on timeout, passing the execution context, the timeout applied, the capturing the abandoned, timed-out action, and the captured . + /// An action to call on timeout, passing the execution context, the timeout applied, the capturing the abandoned, timed-out action, and the captured . /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeoutProvider @@ -347,7 +347,7 @@ public static AsyncTimeoutPolicy TimeoutAsync(Func /// A function to provide the timeout for this execution. /// The timeout strategy. - /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. + /// An action to call on timeout, passing the execution context, the timeout applied, and a capturing the abandoned, timed-out action. /// The Task parameter will be null if the executed action responded cooperatively to cancellation before the policy timed it out. /// The policy instance. /// timeoutProvider diff --git a/src/Polly/Timeout/TimeoutEngine.cs b/src/Polly/Timeout/TimeoutEngine.cs index 9371fc100e0..81b1816d8d5 100644 --- a/src/Polly/Timeout/TimeoutEngine.cs +++ b/src/Polly/Timeout/TimeoutEngine.cs @@ -40,7 +40,7 @@ internal static TResult Implementation( actionTask = Task.Run(() => action(context, combinedToken) // cancellation token here allows the user delegate to react to cancellation: possibly clear up; then throw an OperationCanceledException. - , combinedToken); // cancellation token here only allows Task.Run() to not begin the passed delegate at all, if cancellation occurs prior to invoking the delegate. + , combinedToken); // cancellation token here only allows Task.Run() to not begin the passed delegate at all, if cancellation occurs prior to invoking the delegate. try { actionTask.Wait(timeoutCancellationTokenSource.Token); // cancellation token here cancels the Wait() and causes it to throw, but does not cancel actionTask. We use only timeoutCancellationTokenSource.Token here, not combinedToken. If we allowed the user's cancellation token to cancel the Wait(), in this pessimistic scenario where the user delegate may not observe that cancellation, that would create a no-longer-observed task. That task could in turn later fault before completing, risking an UnobservedTaskException. diff --git a/src/Polly/Timeout/TimeoutPolicy.cs b/src/Polly/Timeout/TimeoutPolicy.cs index 45098c040a3..a6b0621078c 100644 --- a/src/Polly/Timeout/TimeoutPolicy.cs +++ b/src/Polly/Timeout/TimeoutPolicy.cs @@ -17,7 +17,7 @@ public class TimeoutPolicy : Policy, ITimeoutPolicy internal TimeoutPolicy( Func timeoutProvider, TimeoutStrategy timeoutStrategy, - Action onTimeout) + Action onTimeout) { _timeoutProvider = timeoutProvider ?? throw new ArgumentNullException(nameof(timeoutProvider)); _timeoutStrategy = timeoutStrategy; diff --git a/src/Polly/Utilities/SystemClock.cs b/src/Polly/Utilities/SystemClock.cs index 51d6fc84ae0..d2ea47c77c6 100644 --- a/src/Polly/Utilities/SystemClock.cs +++ b/src/Polly/Utilities/SystemClock.cs @@ -43,7 +43,7 @@ public static class SystemClock public static Action CancelTokenAfter = (tokenSource, timespan) => tokenSource.CancelAfter(timespan); /// - /// Resets the custom implementations to their defaults. + /// Resets the custom implementations to their defaults. /// Should be called during test teardowns. /// public static void Reset() diff --git a/src/Polly/Utilities/TimedLock.cs b/src/Polly/Utilities/TimedLock.cs index 8d01774a39a..ba9296378b9 100644 --- a/src/Polly/Utilities/TimedLock.cs +++ b/src/Polly/Utilities/TimedLock.cs @@ -17,8 +17,8 @@ namespace Polly.Utilities; internal struct TimedLock : IDisposable { // The TimedLock class throws a LockTimeoutException if a lock cannot be obtained within the LockTimeout. This allows the easier discovery and debugging of deadlocks during Polly development, than if using a pure lock. - // We do not however ever want to throw a LockTimeoutException in production - hence the forked LockTimeout value below for DEBUG versus RELEASE builds. - // This applies particularly because CircuitBreakerPolicy runs state-change delegates during the lock, in order that the state change holds true (cannot be superseded by activity on other threads) while the delegate runs. + // We do not however ever want to throw a LockTimeoutException in production - hence the forked LockTimeout value below for DEBUG versus RELEASE builds. + // This applies particularly because CircuitBreakerPolicy runs state-change delegates during the lock, in order that the state change holds true (cannot be superseded by activity on other threads) while the delegate runs. #if DEBUG private static readonly TimeSpan LockTimeout = TimeSpan.FromSeconds(5); #else diff --git a/src/Polly/Wrap/AsyncPolicyWrap.cs b/src/Polly/Wrap/AsyncPolicyWrap.cs index af3e77e5117..90effaebef1 100644 --- a/src/Polly/Wrap/AsyncPolicyWrap.cs +++ b/src/Polly/Wrap/AsyncPolicyWrap.cs @@ -55,7 +55,7 @@ protected override Task ImplementationAsync(Func ImplementationAsync( IAsyncPolicy innerPolicy) => await outerPolicy.ExecuteAsync( async (ctx, ct) => await innerPolicy.ExecuteAsync( - func, - ctx, - ct, + func, + ctx, + ct, continueOnCapturedContext - ).ConfigureAwait(continueOnCapturedContext), - context, - cancellationToken, + ).ConfigureAwait(continueOnCapturedContext), + context, + cancellationToken, continueOnCapturedContext ).ConfigureAwait(continueOnCapturedContext); diff --git a/src/Polly/Wrap/PolicyWrap.cs b/src/Polly/Wrap/PolicyWrap.cs index aef1864cfb0..1cbbf3bf64d 100644 --- a/src/Polly/Wrap/PolicyWrap.cs +++ b/src/Polly/Wrap/PolicyWrap.cs @@ -22,7 +22,7 @@ public partial class PolicyWrap : Policy, IPolicyWrap /// public IsPolicy Inner => _inner; - internal PolicyWrap(Policy outer, ISyncPolicy inner) + internal PolicyWrap(Policy outer, ISyncPolicy inner) : base(outer.ExceptionPredicates) { _outer = outer; diff --git a/src/Polly/Wrap/PolicyWrapEngine.cs b/src/Polly/Wrap/PolicyWrapEngine.cs index a0809615535..508882d272c 100644 --- a/src/Polly/Wrap/PolicyWrapEngine.cs +++ b/src/Polly/Wrap/PolicyWrapEngine.cs @@ -40,7 +40,7 @@ internal static TResult Implementation( internal static void Implementation( Action action, Context context, - CancellationToken cancellationToken, + CancellationToken cancellationToken, ISyncPolicy outerPolicy, ISyncPolicy innerPolicy) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(action, ctx, ct), context, cancellationToken);