diff --git a/test/.editorconfig b/test/.editorconfig index c9cba59763a..fb4a73bd968 100644 --- a/test/.editorconfig +++ b/test/.editorconfig @@ -1,2 +1,6 @@ [*.cs] + +dotnet_diagnostic.CA1062.severity = none +dotnet_diagnostic.SA1204.severity = none +dotnet_diagnostic.SA1600.severity = none dotnet_diagnostic.xUnit1031.severity = suggestion diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj index bceada5ec70..da9c9f2e9d1 100644 --- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj +++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj @@ -6,7 +6,7 @@ Test enable 100 - $(NoWarn);S6966;SA1600;SA1204 + $(NoWarn);S6966 [Polly.Core]* true diff --git a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj index 7db495410fa..21c8438c8c9 100644 --- a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj +++ b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj @@ -5,7 +5,6 @@ Test enable 100 - $(NoWarn);SA1600;SA1204 [Polly.Extensions]* diff --git a/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj b/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj index 23cf1166060..81d2430ef1d 100644 --- a/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj +++ b/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj @@ -5,7 +5,6 @@ Test enable 100 - $(NoWarn);SA1600;SA1204 [Polly.RateLimiting]* diff --git a/test/Polly.Specs/.editorconfig b/test/Polly.Specs/.editorconfig new file mode 100644 index 00000000000..78ad697eb39 --- /dev/null +++ b/test/Polly.Specs/.editorconfig @@ -0,0 +1,7 @@ +[*.cs] + +dotnet_diagnostic.CA1030.severity = none +dotnet_diagnostic.CA2008.severity = none +dotnet_diagnostic.CA2201.severity = none +dotnet_diagnostic.S104.severity = none +dotnet_diagnostic.S6966.severity = none diff --git a/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs index 3d9b77e3dcd..8780feba8b7 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs @@ -1,13 +1,8 @@ namespace Polly.Specs.Bulkhead; [Collection(Constants.ParallelThreadDependentTestCollection)] -public class BulkheadSpecs : BulkheadSpecsBase +public class BulkheadSpecs(ITestOutputHelper testOutputHelper) : BulkheadSpecsBase(testOutputHelper) { - public BulkheadSpecs(ITestOutputHelper testOutputHelper) - : base(testOutputHelper) - { - } - #region Configuration [Fact] diff --git a/test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs b/test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs index a7570fa40d0..ca8d15d5e6b 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs @@ -12,7 +12,7 @@ public abstract class BulkheadSpecsBase : IDisposable #region Time constraints protected readonly TimeSpan ShimTimeSpan = TimeSpan.FromMilliseconds(50); // How frequently to retry the assertions. - protected readonly TimeSpan CohesionTimeLimit = TimeSpan.FromMilliseconds(1000); // Consider increasing CohesionTimeLimit if bulkhead specs fail transiently in slower build environments. + protected readonly TimeSpan CohesionTimeLimit = TimeSpan.FromSeconds(1); #endregion @@ -33,9 +33,9 @@ protected BulkheadSpecsBase(ITestOutputHelper testOutputHelper) protected IBulkheadPolicy BulkheadForStats { get; set; } = null!; - internal TraceableAction[] Actions { get; set; } = { }; + internal TraceableAction[] Actions { get; set; } = []; - protected Task[] Tasks { get; set; } = { }; + protected Task[] Tasks { get; set; } = []; protected readonly AutoResetEvent StatusChangedEvent = new(false); @@ -84,10 +84,7 @@ protected BulkheadSpecsBase(ITestOutputHelper testOutputHelper) [ClassData(typeof(BulkheadScenarios))] public void Should_control_executions_per_specification(int maxParallelization, int maxQueuingActions, int totalActions, bool cancelQueuing, bool cancelExecuting, string scenario) { - if (totalActions < 0) - { - throw new ArgumentOutOfRangeException(nameof(totalActions)); - } + totalActions.ShouldBeGreaterThanOrEqualTo(0); MaxParallelization = maxParallelization; MaxQueuingActions = maxQueuingActions; @@ -312,7 +309,7 @@ protected void EnsureNoUnbservedTaskExceptions() } catch (Exception e) { - throw new Exception("Task " + i + " raised the following unobserved task exception: ", e); + throw new Exception($"Task {i} raised the following unobserved task exception: ", e); } } } @@ -373,6 +370,7 @@ protected void OutputStatus(string statusHeading) private void ShowTestOutput() => ((AnnotatedOutputHelper)TestOutputHelper).Flush(); #endif + #endregion public void Dispose() diff --git a/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs index 6d317344f89..e92906d5ffb 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs @@ -124,7 +124,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu Policy.BulkheadAsync(maxParallelization, maxQueuingActions); protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) => - action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead); + action.ExecuteOnBulkheadAsync((AsyncBulkheadPolicy)bulkhead); #endregion } diff --git a/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs index 94994fcdb6f..1ee025efe3a 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs @@ -124,7 +124,7 @@ protected override IBulkheadPolicy GetBulkhead(int maxParallelization, int maxQu Policy.Bulkhead(maxParallelization, maxQueuingActions); protected override Task ExecuteOnBulkhead(IBulkheadPolicy bulkhead, TraceableAction action) => - action.ExecuteOnBulkhead((BulkheadPolicy)bulkhead); + action.ExecuteOnBulkhead((BulkheadPolicy)bulkhead); #endregion } diff --git a/test/Polly.Specs/Bulkhead/IBulkheadPolicySpecs.cs b/test/Polly.Specs/Bulkhead/IBulkheadPolicySpecs.cs index 8b31ef3a621..566dd469646 100644 --- a/test/Polly.Specs/Bulkhead/IBulkheadPolicySpecs.cs +++ b/test/Polly.Specs/Bulkhead/IBulkheadPolicySpecs.cs @@ -5,7 +5,7 @@ public class IBulkheadPolicySpecs [Fact] public void Should_be_able_to_use_BulkheadAvailableCount_via_interface() { - IBulkheadPolicy bulkhead = Policy.Bulkhead(20, 10); + var bulkhead = Policy.Bulkhead(20, 10); bulkhead.BulkheadAvailableCount.ShouldBe(20); } @@ -13,7 +13,7 @@ public void Should_be_able_to_use_BulkheadAvailableCount_via_interface() [Fact] public void Should_be_able_to_use_QueueAvailableCount_via_interface() { - IBulkheadPolicy bulkhead = Policy.Bulkhead(20, 10); + var bulkhead = Policy.Bulkhead(20, 10); bulkhead.QueueAvailableCount.ShouldBe(10); } diff --git a/test/Polly.Specs/Caching/CacheAsyncSpecs.cs b/test/Polly.Specs/Caching/CacheAsyncSpecs.cs index 535bdab48e9..c9eee27eb0e 100644 --- a/test/Polly.Specs/Caching/CacheAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/CacheAsyncSpecs.cs @@ -313,7 +313,7 @@ public void Should_throw_when_policies_is_null() Action action = () => Policy.WrapAsync(policies); Should.Throw(action).ParamName.ShouldBe("policies"); - action = () => Policy.WrapAsync(policiesGeneric); + action = () => Policy.WrapAsync(policiesGeneric); Should.Throw(action).ParamName.ShouldBe("policies"); } #endregion diff --git a/test/Polly.Specs/Caching/CacheSpecs.cs b/test/Polly.Specs/Caching/CacheSpecs.cs index 31b06bc23b3..3251345b7dc 100644 --- a/test/Polly.Specs/Caching/CacheSpecs.cs +++ b/test/Polly.Specs/Caching/CacheSpecs.cs @@ -312,7 +312,7 @@ public void Should_throw_when_policies_is_null() Action action = () => Policy.Wrap(policies); Should.Throw(action).ParamName.ShouldBe("policies"); - action = () => Policy.Wrap(policiesGeneric); + action = () => Policy.Wrap(policiesGeneric); Should.Throw(action).ParamName.ShouldBe("policies"); } diff --git a/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs b/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs index 9b1d093761b..293bfdec1e3 100644 --- a/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs @@ -321,7 +321,7 @@ public async Task Should_allow_custom_ICacheKeyStrategy() var stubCacheProvider = new StubCacheProvider(); var cacheKeyStrategy = new StubCacheKeyStrategy(context => context.OperationKey + context["id"]); - var cache = Policy.CacheAsync(stubCacheProvider.AsyncFor(), new RelativeTtl(TimeSpan.MaxValue), cacheKeyStrategy, emptyDelegate, emptyDelegate, emptyDelegate, noErrorHandling, noErrorHandling); + var cache = Policy.CacheAsync(stubCacheProvider.AsyncFor(), new RelativeTtl(TimeSpan.MaxValue), cacheKeyStrategy, emptyDelegate, emptyDelegate, emptyDelegate, noErrorHandling, noErrorHandling); object person1 = new ResultClass(ResultPrimitive.Good, "person1"); await stubCacheProvider.PutAsync("person1", person1, new Ttl(TimeSpan.MaxValue), CancellationToken, false); diff --git a/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs b/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs index 0dee9d99850..e941a12319e 100644 --- a/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs @@ -9,9 +9,9 @@ public async Task Should_not_error_for_executions_on_non_nullable_types_if_cache const string OperationKey = "SomeOperationKey"; bool onErrorCalled = false; - Action onError = (_, _, _) => { onErrorCalled = true; }; + Action onError = (_, _, _) => onErrorCalled = true; - IAsyncCacheProvider stubCacheProvider = new StubCacheProvider(); + var stubCacheProvider = new StubCacheProvider(); var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue, onError); (bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken.None, false); @@ -34,7 +34,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_for_non_nullabl const string OperationKey = "SomeOperationKey"; var cancellationToken = CancellationToken.None; - IAsyncCacheProvider stubCacheProvider = new StubCacheProvider(); + var stubCacheProvider = new StubCacheProvider(); var cache = Policy.CacheAsync(stubCacheProvider, TimeSpan.MaxValue); (bool cacheHit1, object? fromCache1) = await stubCacheProvider.TryGetAsync(OperationKey, cancellationToken, false); diff --git a/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs b/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs index 42c5a505b75..381835a3246 100644 --- a/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs +++ b/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs @@ -29,7 +29,7 @@ public void Should_execute_delegate_and_put_value_in_cache_for_non_nullable_type const ResultPrimitive ValueToReturn = ResultPrimitive.Substitute; const string OperationKey = "SomeOperationKey"; - ISyncCacheProvider stubCacheProvider = new StubCacheProvider(); + var stubCacheProvider = new StubCacheProvider(); CachePolicy cache = Policy.Cache(stubCacheProvider, TimeSpan.MaxValue); (bool cacheHit1, object? fromCache1) = stubCacheProvider.TryGet(OperationKey); diff --git a/test/Polly.Specs/CircuitBreaker/ICircuitBreakerTResultPolicySpecs.cs b/test/Polly.Specs/CircuitBreaker/ICircuitBreakerTResultPolicySpecs.cs index b2b9fdd1612..834f27c908e 100644 --- a/test/Polly.Specs/CircuitBreaker/ICircuitBreakerTResultPolicySpecs.cs +++ b/test/Polly.Specs/CircuitBreaker/ICircuitBreakerTResultPolicySpecs.cs @@ -5,7 +5,7 @@ public class ICircuitBreakerTResultPolicySpecs [Fact] public void Should_be_able_to_use_LastHandledResult_via_interface() { - ICircuitBreakerPolicy breaker = Policy + var breaker = Policy .HandleResult(ResultPrimitive.Fault) .CircuitBreaker(2, TimeSpan.FromMinutes(1)); diff --git a/test/Polly.Specs/Custom/CustomTResultAsyncSpecs.cs b/test/Polly.Specs/Custom/CustomTResultAsyncSpecs.cs index c76b9309b03..e7295bc643e 100644 --- a/test/Polly.Specs/Custom/CustomTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Custom/CustomTResultAsyncSpecs.cs @@ -36,7 +36,7 @@ public void Should_be_able_to_construct_reactive_policy() { Action construct = () => { - AsyncAddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviourAsync(async outcome => + AsyncAddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviourAsync(async outcome => { // Placeholder for more substantive async work. Console.WriteLine("Handling " + outcome.Result); @@ -52,7 +52,7 @@ public async Task Reactive_policy_should_handle_result() { ResultPrimitive handled = ResultPrimitive.Undefined; AsyncAddBehaviourIfHandlePolicy policy = Policy - .HandleResult(ResultPrimitive.Fault) + .HandleResult(ResultPrimitive.Fault) .WithBehaviourAsync(async outcome => { handled = outcome.Result; await Task.CompletedTask; }); ResultPrimitive toReturn = ResultPrimitive.Fault; @@ -75,7 +75,7 @@ public async Task Reactive_policy_should_be_able_to_ignore_unhandled_result() { ResultPrimitive? handled = null; AsyncAddBehaviourIfHandlePolicy policy = Policy - .HandleResult(ResultPrimitive.Fault) + .HandleResult(ResultPrimitive.Fault) .WithBehaviourAsync(async outcome => { handled = outcome.Result; await Task.CompletedTask; }); ResultPrimitive toReturn = ResultPrimitive.FaultYetAgain; diff --git a/test/Polly.Specs/Custom/CustomTResultSpecs.cs b/test/Polly.Specs/Custom/CustomTResultSpecs.cs index 4df2d232fe0..163e8b4fdd8 100644 --- a/test/Polly.Specs/Custom/CustomTResultSpecs.cs +++ b/test/Polly.Specs/Custom/CustomTResultSpecs.cs @@ -36,7 +36,7 @@ public void Should_be_able_to_construct_reactive_policy() { Action construct = () => { - AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => Console.WriteLine("Handling " + outcome.Result)); + AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => Console.WriteLine("Handling " + outcome.Result)); }; Should.NotThrow(construct); @@ -46,7 +46,7 @@ public void Should_be_able_to_construct_reactive_policy() public void Reactive_policy_should_handle_result() { ResultPrimitive handled = ResultPrimitive.Undefined; - AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => handled = outcome.Result); + AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => handled = outcome.Result); ResultPrimitive toReturn = ResultPrimitive.Fault; bool executed = false; @@ -66,7 +66,7 @@ public void Reactive_policy_should_handle_result() public void Reactive_policy_should_be_able_to_ignore_unhandled_result() { ResultPrimitive? handled = null; - AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => handled = outcome.Result); + AddBehaviourIfHandlePolicy policy = Policy.HandleResult(ResultPrimitive.Fault).WithBehaviour(outcome => handled = outcome.Result); ResultPrimitive toReturn = ResultPrimitive.FaultYetAgain; bool executed = false; diff --git a/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs b/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs index ab80fcde70d..a93061cd200 100644 --- a/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs +++ b/test/Polly.Specs/Fallback/FallbackAsyncSpecs.cs @@ -245,7 +245,7 @@ public async Task Should_throw_for_generic_method_execution_on_non_generic_polic .Handle() .FallbackAsync(_ => TaskHelper.EmptyTask); - await Should.ThrowAsync(() => fallbackPolicy.ExecuteAsync(() => Task.FromResult(0))); + await Should.ThrowAsync(() => fallbackPolicy.ExecuteAsync(() => Task.FromResult(0))); } #endregion diff --git a/test/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs b/test/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs index fb12e83c9fa..95b72cce7f1 100644 --- a/test/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs +++ b/test/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs @@ -4,14 +4,14 @@ /// A traceable action that can be executed on a , to support specs. /// We can execute multiple instances of in parallel on a bulkhead, and manually control the cancellation and completion of each, to provide determinate tests on the bulkhead operation. The status of this as it executes is fully traceable through the property. /// -public class TraceableAction : IDisposable +public class TraceableAction(int id, AutoResetEvent statusChanged, ITestOutputHelper testOutputHelper) : IDisposable { - private readonly string _id; - private readonly ITestOutputHelper _testOutputHelper; + private readonly string _id = $"{id:00}: "; + private readonly ITestOutputHelper _testOutputHelper = testOutputHelper; private readonly TaskCompletionSource _tcsProxyForRealWork = new(); private readonly CancellationTokenSource _cancellationSource = new(); - private readonly AutoResetEvent _statusChanged; + private readonly AutoResetEvent _statusChanged = statusChanged; private TraceableActionStatus _status; @@ -26,13 +26,6 @@ public TraceableActionStatus Status } } - public TraceableAction(int id, AutoResetEvent statusChanged, ITestOutputHelper testOutputHelper) - { - _id = $"{id:00}: "; - _statusChanged = statusChanged; - _testOutputHelper = testOutputHelper; - } - public void SignalStateChange() { _testOutputHelper.WriteLine("--signalled--"); @@ -99,7 +92,9 @@ private Task ExecuteThroughSyncBulkheadOuter(Action executeThroughBulkheadInner) throw; } } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) +#pragma warning restore CA1031 // Do not catch general exception types { _testOutputHelper.WriteLine(_id + "Caught unexpected exception during execution: " + e); @@ -165,7 +160,9 @@ public Task ExecuteThroughAsyncBulkheadOuter(Func executeThroughBulkheadIn Status = TraceableActionStatus.Canceled; } // else: was execution cancellation rethrown: ignore } +#pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) +#pragma warning restore CA1031 // Do not catch general exception types { _testOutputHelper.WriteLine(_id + "Caught unexpected exception during execution: " + e); @@ -233,6 +230,9 @@ public void Cancel() _tcsProxyForRealWork.SetCanceled(); } - public void Dispose() => + public void Dispose() + { + _statusChanged?.Dispose(); _cancellationSource.Dispose(); + } } diff --git a/test/Polly.Specs/Helpers/Constants.cs b/test/Polly.Specs/Helpers/Constants.cs index 6a4c1d2331f..824c1a5427b 100644 --- a/test/Polly.Specs/Helpers/Constants.cs +++ b/test/Polly.Specs/Helpers/Constants.cs @@ -6,12 +6,14 @@ public static class Constants { /// - /// Denotes a test collection dependent on manipulating the abstracted . These tests are not parallelized. + /// Denotes a test collection dependent on manipulating the abstracted . /// + /// These tests are not parallelized. public const string SystemClockDependentTestCollection = "SystemClockDependentTestCollection"; /// - /// Denotes a test collection making heavy use of parallel threads. These tests are not run in parallel with each other, to reduce heavy use of threads in the build/CI environment. + /// Denotes a test collection making heavy use of parallel threads. /// + /// These tests are not run in parallel with each other, to reduce heavy use of threads in the build/CI environment. public const string ParallelThreadDependentTestCollection = "ParallelThreadDependentTestCollection"; } diff --git a/test/Polly.Specs/Helpers/ContextualPolicyTResultExtensionsAsync.cs b/test/Polly.Specs/Helpers/ContextualPolicyTResultExtensionsAsync.cs index c2730d76c79..1f185841d88 100644 --- a/test/Polly.Specs/Helpers/ContextualPolicyTResultExtensionsAsync.cs +++ b/test/Polly.Specs/Helpers/ContextualPolicyTResultExtensionsAsync.cs @@ -2,10 +2,11 @@ public static class ContextualPolicyTResultExtensionsAsync { - public static Task RaiseResultSequenceAsync(this AsyncPolicy policy, -IDictionary contextData, -params TResult[] resultsToRaise) => - policy.RaiseResultSequenceAsync(contextData, CancellationToken.None, resultsToRaise.ToList()); + public static Task RaiseResultSequenceAsync( + this AsyncPolicy policy, + IDictionary contextData, + params TResult[] resultsToRaise) => + policy.RaiseResultSequenceAsync(contextData, CancellationToken.None, [.. resultsToRaise]); public static Task RaiseResultSequenceAsync(this AsyncPolicy policy, IDictionary contextData, CancellationToken cancellationToken, IEnumerable resultsToRaise) { diff --git a/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandleSyntax.cs b/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandleSyntax.cs index 43f9f0769fa..69042e4981b 100644 --- a/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandleSyntax.cs +++ b/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AddBehaviourIfHandleSyntax.cs @@ -4,21 +4,13 @@ internal static class AddBehaviourIfHandleSyntax { internal static AddBehaviourIfHandlePolicy WithBehaviour(this PolicyBuilder policyBuilder, Action behaviourIfHandle) { - if (behaviourIfHandle == null) - { - throw new ArgumentNullException(nameof(behaviourIfHandle)); - } - + behaviourIfHandle.ShouldNotBeNull(); return new AddBehaviourIfHandlePolicy(behaviourIfHandle, policyBuilder); } internal static AddBehaviourIfHandlePolicy WithBehaviour(this PolicyBuilder policyBuilder, Action> behaviourIfHandle) { - if (behaviourIfHandle == null) - { - throw new ArgumentNullException(nameof(behaviourIfHandle)); - } - + behaviourIfHandle.ShouldNotBeNull(); return new AddBehaviourIfHandlePolicy(behaviourIfHandle, policyBuilder); } } diff --git a/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs b/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs index 18796a6a47f..b0781c0c135 100644 --- a/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs +++ b/test/Polly.Specs/Helpers/Custom/AddBehaviourIfHandle/AsyncAddBehaviourIfHandlePolicy.cs @@ -10,7 +10,7 @@ internal AsyncAddBehaviourIfHandlePolicy( : base(policyBuilder) => _behaviourIfHandle = behaviourIfHandle ?? throw new ArgumentNullException(nameof(behaviourIfHandle)); - protected override Task ImplementationAsync(Func> action, Context context, System.Threading.CancellationToken cancellationToken, + protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => AsyncAddBehaviourIfHandleEngine.ImplementationAsync( ExceptionPredicates, @@ -32,7 +32,7 @@ internal AsyncAddBehaviourIfHandlePolicy( : base(policyBuilder) => _behaviourIfHandle = behaviourIfHandle ?? throw new ArgumentNullException(nameof(behaviourIfHandle)); - protected override Task ImplementationAsync(Func> action, Context context, System.Threading.CancellationToken cancellationToken, + protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => AsyncAddBehaviourIfHandleEngine.ImplementationAsync( ExceptionPredicates, diff --git a/test/Polly.Specs/Helpers/PolicyExtensions.cs b/test/Polly.Specs/Helpers/PolicyExtensions.cs index 3ab856364b7..13c592c60d1 100644 --- a/test/Polly.Specs/Helpers/PolicyExtensions.cs +++ b/test/Polly.Specs/Helpers/PolicyExtensions.cs @@ -52,7 +52,7 @@ public static void RaiseException(this Policy policy, int numberOfTi public static void RaiseExceptionAndOrCancellation(this Policy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute) where TException : Exception, new() => - policy.RaiseExceptionAndOrCancellation(scenario, cancellationTokenSource, onExecute, _ => new TException()); + policy.RaiseExceptionAndOrCancellation(scenario, cancellationTokenSource, onExecute, _ => new TException()); public static TResult RaiseExceptionAndOrCancellation(this Policy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute, TResult successResult) where TException : Exception, new() diff --git a/test/Polly.Specs/Helpers/PolicyExtensionsAsync.cs b/test/Polly.Specs/Helpers/PolicyExtensionsAsync.cs index e5e71935c9a..03fb5bb6cba 100644 --- a/test/Polly.Specs/Helpers/PolicyExtensionsAsync.cs +++ b/test/Polly.Specs/Helpers/PolicyExtensionsAsync.cs @@ -54,7 +54,7 @@ public static Task RaiseExceptionAsync(this AsyncPolicy policy, int public static Task RaiseExceptionAndOrCancellationAsync(this AsyncPolicy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute) where TException : Exception, new() => - policy.RaiseExceptionAndOrCancellationAsync(scenario, cancellationTokenSource, onExecute, _ => new TException()); + policy.RaiseExceptionAndOrCancellationAsync(scenario, cancellationTokenSource, onExecute, _ => new TException()); public static Task RaiseExceptionAndOrCancellationAsync(this AsyncPolicy policy, ExceptionAndOrCancellationScenario scenario, CancellationTokenSource cancellationTokenSource, Action onExecute, TResult successResult) where TException : Exception, new() diff --git a/test/Polly.Specs/Helpers/PolicyTResultExtensionsAsync.cs b/test/Polly.Specs/Helpers/PolicyTResultExtensionsAsync.cs index b27f7bbef8d..c546be23743 100644 --- a/test/Polly.Specs/Helpers/PolicyTResultExtensionsAsync.cs +++ b/test/Polly.Specs/Helpers/PolicyTResultExtensionsAsync.cs @@ -18,7 +18,7 @@ public static async Task RaiseResultSequenceAsync(this AsyncPo { if (!enumerator.MoveNext()) { - throw new ArgumentOutOfRangeException(nameof(resultsToRaise), $"Not enough {typeof(TResult).Name} values in {nameof(resultsToRaise)}."); + throw new ArgumentOutOfRangeException(nameof(resultsToRaise), $"Not enough {typeof(TResult).Name} values in {nameof(resultsToRaise)}."); } return Task.FromResult(enumerator.Current); diff --git a/test/Polly.Specs/Helpers/ResultClass.cs b/test/Polly.Specs/Helpers/ResultClass.cs index c7cc8506579..32b1bc1cd5a 100644 --- a/test/Polly.Specs/Helpers/ResultClass.cs +++ b/test/Polly.Specs/Helpers/ResultClass.cs @@ -3,16 +3,14 @@ /// /// A helper class supporting tests on how Policy<TResult> policies handle return results which are class types (as opposed to primitive types). /// -internal class ResultClass +internal class ResultClass(ResultPrimitive resultCode, string? someString) { - public ResultClass(ResultPrimitive resultCode) => - ResultCode = resultCode; + public ResultClass(ResultPrimitive resultCode) + : this(resultCode, null) + { + } - public ResultClass(ResultPrimitive resultCode, string someString) - : this(resultCode) => - SomeString = someString; + public ResultPrimitive ResultCode { get; set; } = resultCode; - public ResultPrimitive ResultCode { get; set; } - - public string? SomeString { get; set; } + public string? SomeString { get; set; } = someString; } diff --git a/test/Polly.Specs/PolicyKeyAsyncSpecs.cs b/test/Polly.Specs/PolicyKeyAsyncSpecs.cs index 8b017a5d5bd..5870ac84e8c 100644 --- a/test/Polly.Specs/PolicyKeyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyKeyAsyncSpecs.cs @@ -120,7 +120,7 @@ public async Task Should_pass_PolicyKey_to_execution_context() string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.Handle().RetryAsync(1, onRetry).WithPolicyKey(policyKey); await retry.RaiseExceptionAsync(1); @@ -134,7 +134,7 @@ public async Task Should_pass_OperationKey_to_execution_context() string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.Handle().RetryAsync(1, onRetry); bool firstExecution = true; @@ -157,11 +157,11 @@ public async Task Should_pass_PolicyKey_to_execution_context_in_generic_executio string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.Handle().RetryAsync(1, onRetry).WithPolicyKey(policyKey); bool firstExecution = true; - await retry.ExecuteAsync(async () => + await retry.ExecuteAsync(async () => { await TaskHelper.EmptyTask; if (firstExecution) @@ -182,7 +182,7 @@ public async Task Should_pass_OperationKey_to_execution_context_in_generic_execu string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.Handle().RetryAsync(1, onRetry); bool firstExecution = true; diff --git a/test/Polly.Specs/PolicyKeySpecs.cs b/test/Polly.Specs/PolicyKeySpecs.cs index 617a72e39f7..b31085eab84 100644 --- a/test/Polly.Specs/PolicyKeySpecs.cs +++ b/test/Polly.Specs/PolicyKeySpecs.cs @@ -101,7 +101,7 @@ public void Should_pass_PolicyKey_to_execution_context() string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.Handle().Retry(1, onRetry).WithPolicyKey(policyKey); retry.RaiseException(1); @@ -115,7 +115,7 @@ public void Should_pass_OperationKey_to_execution_context() string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.Handle().Retry(1, onRetry); bool firstExecution = true; @@ -137,11 +137,11 @@ public void Should_pass_PolicyKey_to_execution_context_in_generic_execution_on_n string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.Handle().Retry(1, onRetry).WithPolicyKey(policyKey); bool firstExecution = true; - retry.Execute(() => + retry.Execute(() => { if (firstExecution) { @@ -161,11 +161,11 @@ public void Should_pass_OperationKey_to_execution_context_in_generic_execution_o string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.Handle().Retry(1, onRetry); bool firstExecution = true; - retry.Execute(_ => + retry.Execute(_ => { if (firstExecution) { diff --git a/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs b/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs index 4b6b3bb1e7a..0dc12e5220e 100644 --- a/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs @@ -7,7 +7,7 @@ public class PolicyTResultKeyAsyncSpecs [Fact] public void Should_be_able_fluently_to_configure_the_policy_key() { - var policy = Policy.HandleResult(0).RetryAsync().WithPolicyKey(Guid.NewGuid().ToString()); + var policy = Policy.HandleResult(0).RetryAsync().WithPolicyKey(Guid.NewGuid().ToString()); policy.ShouldBeAssignableTo>(); } @@ -15,7 +15,7 @@ public void Should_be_able_fluently_to_configure_the_policy_key() [Fact] public void Should_be_able_fluently_to_configure_the_policy_key_via_interface() { - IAsyncPolicy policyAsInterface = Policy.HandleResult(0).RetryAsync(); + IAsyncPolicy policyAsInterface = Policy.HandleResult(0).RetryAsync(); var policyAsInterfaceAfterWithPolicyKey = policyAsInterface.WithPolicyKey(Guid.NewGuid().ToString()); policyAsInterfaceAfterWithPolicyKey.ShouldBeAssignableTo>(); @@ -112,7 +112,7 @@ public async Task Should_pass_PolicyKey_to_execution_context() string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action, int, Context> onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action, int, Context> onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1, onRetry).WithPolicyKey(policyKey); await retry.RaiseResultSequenceAsync(ResultPrimitive.Fault, ResultPrimitive.Good); @@ -126,7 +126,7 @@ public async Task Should_pass_OperationKey_to_execution_context() string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action, int, Context> onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action, int, Context> onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1, onRetry); bool firstExecution = true; diff --git a/test/Polly.Specs/PolicyTResultKeySpecs.cs b/test/Polly.Specs/PolicyTResultKeySpecs.cs index 149e073891a..2158d50c184 100644 --- a/test/Polly.Specs/PolicyTResultKeySpecs.cs +++ b/test/Polly.Specs/PolicyTResultKeySpecs.cs @@ -7,7 +7,7 @@ public class PolicyTResultKeySpecs [Fact] public void Should_be_able_fluently_to_configure_the_policy_key() { - var policy = Policy.HandleResult(0).Retry().WithPolicyKey(Guid.NewGuid().ToString()); + var policy = Policy.HandleResult(0).Retry().WithPolicyKey(Guid.NewGuid().ToString()); policy.ShouldBeAssignableTo>(); } @@ -15,7 +15,7 @@ public void Should_be_able_fluently_to_configure_the_policy_key() [Fact] public void Should_be_able_fluently_to_configure_the_policy_key_via_interface() { - ISyncPolicy policyAsInterface = Policy.HandleResult(0).Retry(); + ISyncPolicy policyAsInterface = Policy.HandleResult(0).Retry(); var policyAsInterfaceAfterWithPolicyKey = policyAsInterface.WithPolicyKey(Guid.NewGuid().ToString()); policyAsInterfaceAfterWithPolicyKey.ShouldBeAssignableTo>(); @@ -101,7 +101,7 @@ public void Should_pass_PolicyKey_to_execution_context() string policyKey = Guid.NewGuid().ToString(); string? policyKeySetOnExecutionContext = null; - Action, int, Context> onRetry = (_, _, context) => { policyKeySetOnExecutionContext = context.PolicyKey; }; + Action, int, Context> onRetry = (_, _, context) => policyKeySetOnExecutionContext = context.PolicyKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1, onRetry).WithPolicyKey(policyKey); retry.RaiseResultSequence(ResultPrimitive.Fault, ResultPrimitive.Good); @@ -115,7 +115,7 @@ public void Should_pass_OperationKey_to_execution_context() string operationKey = "SomeKey"; string? operationKeySetOnContext = null; - Action, int, Context> onRetry = (_, _, context) => { operationKeySetOnContext = context.OperationKey; }; + Action, int, Context> onRetry = (_, _, context) => operationKeySetOnContext = context.OperationKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1, onRetry); bool firstExecution = true; diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj index f87665d32b7..662b680b8bc 100644 --- a/test/Polly.Specs/Polly.Specs.csproj +++ b/test/Polly.Specs/Polly.Specs.csproj @@ -8,9 +8,6 @@ 75,60,70 [Polly]* true - $(NoWarn);CA1030;CA1031;CA2008;CA2201 - $(NoWarn);S104;S6966 - $(NoWarn);SA1402;SA1600 diff --git a/test/Polly.Specs/RateLimit/AsyncRateLimitPolicyTResultSpecs.cs b/test/Polly.Specs/RateLimit/AsyncRateLimitPolicyTResultSpecs.cs index 8e5d4a6cb3f..de33eb804a8 100644 --- a/test/Polly.Specs/RateLimit/AsyncRateLimitPolicyTResultSpecs.cs +++ b/test/Polly.Specs/RateLimit/AsyncRateLimitPolicyTResultSpecs.cs @@ -14,7 +14,7 @@ protected override IRateLimitPolicy GetPolicyViaSyntax(int numberOfExecutions, T protected override IRateLimitPolicy GetPolicyViaSyntax(int numberOfExecutions, TimeSpan perTimeSpan, int maxBurst, Func retryAfterFactory) => - Policy.RateLimitAsync(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory); + Policy.RateLimitAsync(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory); protected override (bool, TimeSpan) TryExecuteThroughPolicy(IRateLimitPolicy policy) { diff --git a/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecs.cs b/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecs.cs index 4d75dad4a2d..bd11d581044 100644 --- a/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecs.cs +++ b/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecs.cs @@ -14,7 +14,7 @@ protected override IRateLimitPolicy GetPolicyViaSyntax(int numberOfExecutions, T protected override IRateLimitPolicy GetPolicyViaSyntax(int numberOfExecutions, TimeSpan perTimeSpan, int maxBurst, Func retryAfterFactory) => - Policy.RateLimit(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory); + Policy.RateLimit(numberOfExecutions, perTimeSpan, maxBurst, retryAfterFactory); protected override (bool, TimeSpan) TryExecuteThroughPolicy(IRateLimitPolicy policy) { diff --git a/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecsBase.cs b/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecsBase.cs index cc45b807e61..9bd19a27e65 100644 --- a/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecsBase.cs +++ b/test/Polly.Specs/RateLimit/RateLimitPolicyTResultSpecsBase.cs @@ -26,7 +26,7 @@ public void Ratelimiter_specifies_correct_wait_until_next_execution_by_custom_fa contextPassedToRetryAfter = ctx; return new ResultClassWithRetryAfter(t); }; - var rateLimiter = GetPolicyViaSyntax(1, onePer, 1, retryAfterFactory); + var rateLimiter = GetPolicyViaSyntax(1, onePer, 1, retryAfterFactory); // Arrange - drain first permitted execution after initialising. ShouldPermitAnExecution(rateLimiter); diff --git a/test/Polly.Specs/Registry/ConcurrentPolicyRegistrySpecs.cs b/test/Polly.Specs/Registry/ConcurrentPolicyRegistrySpecs.cs index b4ff1e05ff0..f54258c4e0d 100644 --- a/test/Polly.Specs/Registry/ConcurrentPolicyRegistrySpecs.cs +++ b/test/Polly.Specs/Registry/ConcurrentPolicyRegistrySpecs.cs @@ -2,10 +2,7 @@ public class ConcurrentPolicyRegistrySpecs { - private readonly IConcurrentPolicyRegistry _registry; - - public ConcurrentPolicyRegistrySpecs() => - _registry = new PolicyRegistry(); + private readonly PolicyRegistry _registry = []; [Fact] public void Should_be_able_to_add_Policy_using_TryAdd() diff --git a/test/Polly.Specs/Registry/PolicyRegistrySpecs.cs b/test/Polly.Specs/Registry/PolicyRegistrySpecs.cs index e7d6b7ffe97..8894b64563d 100644 --- a/test/Polly.Specs/Registry/PolicyRegistrySpecs.cs +++ b/test/Polly.Specs/Registry/PolicyRegistrySpecs.cs @@ -50,7 +50,7 @@ public void Should_be_able_to_add_Policy_by_interface_using_Add() ISyncPolicy policy2 = Policy.HandleResult(ResultPrimitive.Fault).Retry(); string key2 = Guid.NewGuid().ToString(); - _registry.Add>(key2, policy2); + _registry.Add(key2, policy2); _registry.Count.ShouldBe(2); } diff --git a/test/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs b/test/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs index a2b506913e1..b8afec62073 100644 --- a/test/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs +++ b/test/Polly.Specs/Registry/ReadOnlyPolicyRegistrySpecs.cs @@ -2,13 +2,10 @@ public class ReadOnlyPolicyRegistrySpecs { - private readonly IPolicyRegistry _registry; + private readonly PolicyRegistry _registry = []; private IReadOnlyPolicyRegistry ReadOnlyRegistry => _registry; - public ReadOnlyPolicyRegistrySpecs() => - _registry = new PolicyRegistry(); - #region Tests for retrieving policy [Fact] diff --git a/test/Polly.Specs/Retry/RetryTResultSpecs.cs b/test/Polly.Specs/Retry/RetryTResultSpecs.cs index 8b3e5be557b..7f7adb79294 100644 --- a/test/Polly.Specs/Retry/RetryTResultSpecs.cs +++ b/test/Polly.Specs/Retry/RetryTResultSpecs.cs @@ -391,7 +391,7 @@ public void Should_not_call_onretry_when_retry_count_is_zero_without_context() { bool retryInvoked = false; - Action, int> onRetry = (_, _) => { retryInvoked = true; }; + Action, int> onRetry = (_, _) => retryInvoked = true; RetryPolicy policy = Policy .HandleResult(ResultPrimitive.Fault) @@ -407,7 +407,7 @@ public void Should_not_call_onretry_when_retry_count_is_zero_with_context() { bool retryInvoked = false; - Action, int, Context> onRetry = (_, _, _) => { retryInvoked = true; }; + Action, int, Context> onRetry = (_, _, _) => retryInvoked = true; RetryPolicy policy = Policy .HandleResult(ResultPrimitive.Fault) diff --git a/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs b/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs index 474ed0fc718..dbe85fe1fc9 100644 --- a/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs +++ b/test/Polly.Specs/Retry/WaitAndRetrySpecs.cs @@ -1072,7 +1072,7 @@ public void Should_honour_cancellation_immediately_during_wait_phase_of_waitandr attemptsInvoked.ShouldBe(1); watch.Elapsed.ShouldBeLessThan(retryDelay); - watch.Elapsed.ShouldBe(shimTimeSpan, TimeSpan.FromMilliseconds(shimTimeSpan.TotalMilliseconds / 2)); // Consider increasing shimTimeSpan, or loosening precision, if test fails transiently in different environments. + watch.Elapsed.ShouldBe(shimTimeSpan, TimeSpan.FromMilliseconds(shimTimeSpan.TotalMilliseconds / 2)); } [Fact] diff --git a/test/Polly.Specs/Retry/WaitAndRetryTResultSpecs.cs b/test/Polly.Specs/Retry/WaitAndRetryTResultSpecs.cs index 41c82738a47..874f29a4891 100644 --- a/test/Polly.Specs/Retry/WaitAndRetryTResultSpecs.cs +++ b/test/Polly.Specs/Retry/WaitAndRetryTResultSpecs.cs @@ -10,8 +10,8 @@ public void Should_be_able_to_calculate_retry_timespans_based_on_the_handled_fau { Dictionary expectedRetryWaits = new Dictionary { - {ResultPrimitive.Fault, TimeSpan.FromSeconds(2)}, - {ResultPrimitive.FaultAgain, TimeSpan.FromSeconds(4)}, + [ResultPrimitive.Fault] = TimeSpan.FromSeconds(2), + [ResultPrimitive.FaultAgain] = TimeSpan.FromSeconds(4), }; var actualRetryWaits = new List(); diff --git a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs index 4ae8f49abdb..3433dcbe215 100644 --- a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs @@ -228,7 +228,6 @@ public async Task Should_throw_when_timeout_is_less_than_execution_duration__pes await Should.ThrowAsync(() => policy.ExecuteAsync(async () => { await SystemClock.SleepAsync(TimeSpan.FromSeconds(3), CancellationToken); - })); } @@ -261,7 +260,6 @@ public async Task Should_throw_timeout_after_correct_duration__pessimistic() await Should.ThrowAsync(() => policy.ExecuteAsync(async () => { await SystemClock.SleepAsync(TimeSpan.FromSeconds(10), CancellationToken); - })); watch.Stop(); @@ -315,7 +313,6 @@ public async Task Should_throw_when_timeout_is_less_than_execution_duration__opt await Should.ThrowAsync(() => policy.ExecuteAsync(async ct => { await SystemClock.SleepAsync(TimeSpan.FromSeconds(3), ct); - }, userCancellationToken)); } @@ -625,7 +622,7 @@ public async Task Should_call_ontimeout_with_task_wrapping_abandoned_action_allo return TaskHelper.EmptyTask; }; - TimeSpan shimTimespan = TimeSpan.FromSeconds(1); // Consider increasing shimTimeSpan if test fails transiently in different environments. + TimeSpan shimTimespan = TimeSpan.FromSeconds(1); TimeSpan thriceShimTimeSpan = shimTimespan + shimTimespan + shimTimespan; var policy = Policy.TimeoutAsync(shimTimespan, TimeoutStrategy.Pessimistic, onTimeoutAsync); diff --git a/test/Polly.Specs/Timeout/TimeoutSpecs.cs b/test/Polly.Specs/Timeout/TimeoutSpecs.cs index 1ac980b4eb0..3ef3560d330 100644 --- a/test/Polly.Specs/Timeout/TimeoutSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutSpecs.cs @@ -269,7 +269,7 @@ public void Should_throw_timeout_after_correct_duration__pessimistic() TimeSpan timeout = TimeSpan.FromSeconds(1); var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic); - TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. + TimeSpan tolerance = TimeSpan.FromSeconds(3); var watch = Stopwatch.StartNew(); Should.Throw(() => policy.Execute(() => SystemClock.Sleep(TimeSpan.FromSeconds(10), CancellationToken))); @@ -412,7 +412,7 @@ public void Should_throw_timeout_after_correct_duration__optimistic() var policy = Policy.Timeout(timeout); var userCancellationToken = CancellationToken; - TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. + TimeSpan tolerance = TimeSpan.FromSeconds(3); var watch = Stopwatch.StartNew(); @@ -552,7 +552,7 @@ public void Should_call_ontimeout_with_configured_timeout__pessimistic() TimeSpan timeoutPassedToConfiguration = TimeSpan.FromMilliseconds(250); TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutPassedToConfiguration, TimeoutStrategy.Pessimistic, onTimeout); @@ -568,7 +568,7 @@ public void Should_call_ontimeout_with_passed_context__pessimistic() Context contextPassedToExecute = new Context(operationKey); Context? contextPassedToOnTimeout = null; - Action onTimeout = (ctx, _, _) => { contextPassedToOnTimeout = ctx; }; + Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; TimeSpan timeout = TimeSpan.FromMilliseconds(250); var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic, onTimeout); @@ -589,7 +589,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutFunc = () => TimeSpan.FromMilliseconds(25 * programaticallyControlledDelay); TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutFunc, TimeoutStrategy.Pessimistic, onTimeout); @@ -607,7 +607,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutProvider = ctx => (TimeSpan)ctx["timeout"]; TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutProvider, TimeoutStrategy.Pessimistic, onTimeout); // Supply a programatically-controlled timeout, via the execution context. @@ -622,7 +622,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu public void Should_call_ontimeout_with_task_wrapping_abandoned_action__pessimistic() { Task? taskPassedToOnTimeout = null; - Action onTimeout = (_, _, task) => { taskPassedToOnTimeout = task; }; + Action onTimeout = (_, _, task) => taskPassedToOnTimeout = task; TimeSpan timeout = TimeSpan.FromMilliseconds(250); var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic, onTimeout); @@ -648,7 +648,7 @@ public void Should_call_ontimeout_with_task_wrapping_abandoned_action_allowing_c task.ContinueWith(t => exceptionObservedFromTaskPassedToOnTimeout = t.Exception!.InnerException); }; - TimeSpan shimTimespan = TimeSpan.FromSeconds(1); // Consider increasing shimTimeSpan if test fails transiently in different environments. + TimeSpan shimTimespan = TimeSpan.FromSeconds(1); TimeSpan thriceShimTimeSpan = shimTimespan + shimTimespan + shimTimespan; var policy = Policy.Timeout(shimTimespan, TimeoutStrategy.Pessimistic, onTimeout); @@ -670,7 +670,7 @@ public void Should_call_ontimeout_with_timing_out_exception__pessimistic() TimeSpan timeoutPassedToConfiguration = TimeSpan.FromMilliseconds(250); Exception? exceptionPassedToOnTimeout = null; - Action onTimeout = (_, _, _, exception) => { exceptionPassedToOnTimeout = exception; }; + Action onTimeout = (_, _, _, exception) => exceptionPassedToOnTimeout = exception; var policy = Policy.Timeout(timeoutPassedToConfiguration, TimeoutStrategy.Pessimistic, onTimeout); @@ -690,7 +690,7 @@ public void Should_call_ontimeout_with_configured_timeout__optimistic() TimeSpan timeoutPassedToConfiguration = TimeSpan.FromMilliseconds(250); TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutPassedToConfiguration, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; @@ -707,7 +707,7 @@ public void Should_call_ontimeout_with_passed_context__optimistic() Context contextPassedToExecute = new Context(operationKey); Context? contextPassedToOnTimeout = null; - Action onTimeout = (ctx, _, _) => { contextPassedToOnTimeout = ctx; }; + Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; TimeSpan timeout = TimeSpan.FromMilliseconds(250); var policy = Policy.Timeout(timeout, TimeoutStrategy.Optimistic, onTimeout); @@ -729,7 +729,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutFunc = () => TimeSpan.FromMilliseconds(25 * programaticallyControlledDelay); TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutFunc, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; @@ -748,7 +748,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutProvider = ctx => (TimeSpan)ctx["timeout"]; TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutProvider, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; @@ -768,7 +768,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu public void Should_call_ontimeout_but_not_with_task_wrapping_abandoned_action__optimistic() { Task? taskPassedToOnTimeout = null; - Action onTimeout = (_, _, task) => { taskPassedToOnTimeout = task; }; + Action onTimeout = (_, _, task) => taskPassedToOnTimeout = task; TimeSpan timeout = TimeSpan.FromMilliseconds(250); var policy = Policy.Timeout(timeout, TimeoutStrategy.Optimistic, onTimeout); @@ -785,7 +785,7 @@ public void Should_call_ontimeout_with_timing_out_exception__optimistic() TimeSpan timeoutPassedToConfiguration = TimeSpan.FromMilliseconds(250); Exception? exceptionPassedToOnTimeout = null; - Action onTimeout = (_, _, _, exception) => { exceptionPassedToOnTimeout = exception; }; + Action onTimeout = (_, _, _, exception) => exceptionPassedToOnTimeout = exception; var policy = Policy.Timeout(timeoutPassedToConfiguration, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; diff --git a/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs b/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs index c2d9ebd723b..3ea53cc31c3 100644 --- a/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs @@ -248,7 +248,7 @@ public async Task Should_throw_timeout_after_correct_duration__pessimistic() TimeSpan timeout = TimeSpan.FromSeconds(1); var policy = Policy.TimeoutAsync(timeout, TimeoutStrategy.Pessimistic); - TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. + TimeSpan tolerance = TimeSpan.FromSeconds(3); Stopwatch watch = Stopwatch.StartNew(); @@ -308,7 +308,7 @@ public async Task Should_throw_timeout_after_correct_duration__optimistic() var policy = Policy.TimeoutAsync(timeout, TimeoutStrategy.Optimistic); var userCancellationToken = CancellationToken; - TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. + TimeSpan tolerance = TimeSpan.FromSeconds(3); Stopwatch watch = Stopwatch.StartNew(); await Should.ThrowAsync(() => policy.ExecuteAsync(async ct => @@ -561,7 +561,7 @@ public async Task Should_call_ontimeout_with_task_wrapping_abandoned_action_allo return TaskHelper.EmptyTask; }; - TimeSpan shimTimespan = TimeSpan.FromSeconds(1); // Consider increasing shimTimeSpan if test fails transiently in different environments. + TimeSpan shimTimespan = TimeSpan.FromSeconds(1); TimeSpan thriceShimTimeSpan = shimTimespan + shimTimespan + shimTimespan; var policy = Policy.TimeoutAsync(shimTimespan, TimeoutStrategy.Pessimistic, onTimeoutAsync); diff --git a/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs b/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs index 1fead71525a..619c1650491 100644 --- a/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs @@ -256,7 +256,7 @@ public void Should_throw_timeout_after_correct_duration__pessimistic() TimeSpan timeout = TimeSpan.FromSeconds(1); var policy = Policy.Timeout(timeout, TimeoutStrategy.Pessimistic); - TimeSpan tolerance = TimeSpan.FromSeconds(3); // Consider increasing tolerance, if test fails transiently in different test/build environments. + TimeSpan tolerance = TimeSpan.FromSeconds(3); Stopwatch watch = Stopwatch.StartNew(); @@ -591,7 +591,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutProvider = ctx => (TimeSpan)ctx["timeout"]; TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutProvider, TimeoutStrategy.Pessimistic, onTimeout); // Supply a programatically-controlled timeout, via the execution context. @@ -732,7 +732,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutFunc = () => TimeSpan.FromMilliseconds(25 * programaticallyControlledDelay); TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutFunc, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; @@ -755,7 +755,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu Func timeoutProvider = ctx => (TimeSpan)ctx["timeout"]; TimeSpan? timeoutPassedToOnTimeout = null; - Action onTimeout = (_, span, _) => { timeoutPassedToOnTimeout = span; }; + Action onTimeout = (_, span, _) => timeoutPassedToOnTimeout = span; var policy = Policy.Timeout(timeoutProvider, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; @@ -778,7 +778,7 @@ public void Should_call_ontimeout_with_timeout_supplied_different_for_each_execu public void Should_call_ontimeout_but_not_with_task_wrapping_abandoned_action__optimistic() { Task? taskPassedToOnTimeout = null; - Action onTimeout = (_, _, task) => { taskPassedToOnTimeout = task; }; + Action onTimeout = (_, _, task) => taskPassedToOnTimeout = task; TimeSpan timeout = TimeSpan.FromMilliseconds(250); var policy = Policy.Timeout(timeout, TimeoutStrategy.Optimistic, onTimeout); @@ -799,7 +799,7 @@ public void Should_call_ontimeout_with_timing_out_exception__optimistic() TimeSpan timeoutPassedToConfiguration = TimeSpan.FromMilliseconds(250); Exception? exceptionPassedToOnTimeout = null; - Action onTimeout = (_, _, _, exception) => { exceptionPassedToOnTimeout = exception; }; + Action onTimeout = (_, _, _, exception) => exceptionPassedToOnTimeout = exception; var policy = Policy.Timeout(timeoutPassedToConfiguration, TimeoutStrategy.Optimistic, onTimeout); var userCancellationToken = CancellationToken; diff --git a/test/Polly.Specs/Wrap/PolicyWrapAsyncSpecs.cs b/test/Polly.Specs/Wrap/PolicyWrapAsyncSpecs.cs index 29ff2430467..ae227dc5786 100644 --- a/test/Polly.Specs/Wrap/PolicyWrapAsyncSpecs.cs +++ b/test/Polly.Specs/Wrap/PolicyWrapAsyncSpecs.cs @@ -455,7 +455,7 @@ public async Task Outermost_policy_handling_exception_should_report_as_PolicyWra AsyncPolicyWrap wrap = outerHandlingANE.WrapAsync(innerHandlingDBZE); PolicyResult executeAndCaptureResultOnPolicyWrap = - await wrap.ExecuteAndCaptureAsync(() => { throw new ArgumentNullException(); }); + await wrap.ExecuteAndCaptureAsync(() => throw new ArgumentNullException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -474,7 +474,7 @@ public async Task Outermost_policy_not_handling_exception_even_if_inner_policies AsyncPolicyWrap wrap = outerHandlingANE.WrapAsync(innerHandlingDBZE); PolicyResult executeAndCaptureResultOnPolicyWrap = - await wrap.ExecuteAndCaptureAsync(() => { throw new DivideByZeroException(); }); + await wrap.ExecuteAndCaptureAsync(() => throw new DivideByZeroException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -492,7 +492,7 @@ public async Task Outermost_generic_policy_handling_exception_should_report_as_P .CircuitBreakerAsync(1, TimeSpan.Zero); AsyncPolicyWrap wrap = outerHandlingANE.WrapAsync(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = await wrap.ExecuteAndCaptureAsync(() => { throw new ArgumentNullException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = await wrap.ExecuteAndCaptureAsync(() => throw new ArgumentNullException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -511,7 +511,7 @@ public async Task Outermost_generic_policy_not_handling_exception_even_if_inner_ .CircuitBreakerAsync(1, TimeSpan.Zero); AsyncPolicyWrap wrap = outerHandlingANE.WrapAsync(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = await wrap.ExecuteAndCaptureAsync(() => { throw new DivideByZeroException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = await wrap.ExecuteAndCaptureAsync(() => throw new DivideByZeroException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); diff --git a/test/Polly.Specs/Wrap/PolicyWrapContextAndKeyAsyncSpecs.cs b/test/Polly.Specs/Wrap/PolicyWrapContextAndKeyAsyncSpecs.cs index 8cea563ff91..ed33e5019a1 100644 --- a/test/Polly.Specs/Wrap/PolicyWrapContextAndKeyAsyncSpecs.cs +++ b/test/Polly.Specs/Wrap/PolicyWrapContextAndKeyAsyncSpecs.cs @@ -13,10 +13,7 @@ public async Task Should_pass_PolicyKey_to_execution_context_of_outer_policy_as_ string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onRetry = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; var retry = Policy.Handle().RetryAsync(1, onRetry).WithPolicyKey(retryKey); var breaker = Policy.Handle().CircuitBreakerAsync(1, TimeSpan.Zero).WithPolicyKey(breakerKey); @@ -38,10 +35,7 @@ public async Task Should_pass_PolicyKey_to_execution_context_of_inner_policy_as_ string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action onReset = _ => { }; var retry = Policy.Handle().RetryAsync(1).WithPolicyKey(retryKey); @@ -122,10 +116,7 @@ public async Task Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_ignoring_i string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.Handle().RetryAsync(1).WithPolicyKey(retryKey); @@ -154,10 +145,7 @@ public async Task Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_to_innermo string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.Handle().RetryAsync(1).WithPolicyKey(retryKey); @@ -204,10 +192,7 @@ public async Task Should_pass_PolicyKey_to_execution_context_of_outer_policy_as_ string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, int, Context> onRetry = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, int, Context> onRetry = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1, onRetry).WithPolicyKey(retryKey); var breaker = Policy.HandleResult(ResultPrimitive.Fault).CircuitBreakerAsync(1, TimeSpan.Zero).WithPolicyKey(breakerKey); @@ -228,10 +213,7 @@ public async Task Should_pass_PolicyKey_to_execution_context_of_inner_policy_as_ string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, TimeSpan, Context> onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, TimeSpan, Context> onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action onReset = _ => { }; var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1).WithPolicyKey(retryKey); @@ -315,10 +297,7 @@ public async Task Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_ignoring_i string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, TimeSpan, Context> onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, TimeSpan, Context> onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.HandleResult(ResultPrimitive.Fault).RetryAsync(1).WithPolicyKey(retryKey); diff --git a/test/Polly.Specs/Wrap/PolicyWrapContextAndKeySpecs.cs b/test/Polly.Specs/Wrap/PolicyWrapContextAndKeySpecs.cs index 19417b61416..2f5b2c061d6 100644 --- a/test/Polly.Specs/Wrap/PolicyWrapContextAndKeySpecs.cs +++ b/test/Polly.Specs/Wrap/PolicyWrapContextAndKeySpecs.cs @@ -13,10 +13,7 @@ public void Should_pass_PolicyKey_to_execution_context_of_outer_policy_as_Policy string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onRetry = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onRetry = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; var retry = Policy.Handle().Retry(1, onRetry).WithPolicyKey(retryKey); var breaker = Policy.Handle().CircuitBreaker(1, TimeSpan.Zero).WithPolicyKey(breakerKey); @@ -38,10 +35,7 @@ public void Should_pass_PolicyKey_to_execution_context_of_inner_policy_as_Policy string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action onReset = _ => { }; var retry = Policy.Handle().Retry(1).WithPolicyKey(retryKey); @@ -93,10 +87,7 @@ public void Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_ignoring_inner_P string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.Handle().Retry(1).WithPolicyKey(retryKey); @@ -125,10 +116,7 @@ public void Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_to_innermost_Pol string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.Handle().Retry(1).WithPolicyKey(retryKey); @@ -171,10 +159,7 @@ public void Should_pass_PolicyKey_to_execution_context_of_outer_policy_as_Policy string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, int, Context> onRetry = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, int, Context> onRetry = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1, onRetry).WithPolicyKey(retryKey); var breaker = Policy.HandleResult(ResultPrimitive.Fault).CircuitBreaker(1, TimeSpan.Zero).WithPolicyKey(breakerKey); @@ -195,10 +180,7 @@ public void Should_pass_PolicyKey_to_execution_context_of_inner_policy_as_Policy string wrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, TimeSpan, Context> onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, TimeSpan, Context> onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action onReset = _ => { }; var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1).WithPolicyKey(retryKey); @@ -217,7 +199,7 @@ public void Should_restore_PolicyKey_of_outer_policy_to_execution_context_as_mov { ISyncPolicy fallback = Policy .Handle() - .Fallback(ResultPrimitive.Undefined, onFallback: (_, context) => + .Fallback(ResultPrimitive.Undefined, onFallback: (_, context) => { context.PolicyWrapKey.ShouldBe("PolicyWrap"); context.PolicyKey.ShouldBe("FallbackPolicy"); @@ -249,10 +231,7 @@ public void Should_pass_outmost_PolicyWrap_Key_as_PolicyWrapKey_ignoring_inner_P string outerWrapKey = Guid.NewGuid().ToString(); string? policyWrapKeySetOnExecutionContext = null; - Action, TimeSpan, Context> onBreak = (_, _, context) => - { - policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; - }; + Action, TimeSpan, Context> onBreak = (_, _, context) => policyWrapKeySetOnExecutionContext = context.PolicyWrapKey; Action doNothingOnReset = _ => { }; var retry = Policy.HandleResult(ResultPrimitive.Fault).Retry(1).WithPolicyKey(retryKey); diff --git a/test/Polly.Specs/Wrap/PolicyWrapSpecs.cs b/test/Polly.Specs/Wrap/PolicyWrapSpecs.cs index a1cdcfc3b6a..4c7c56fb1ae 100644 --- a/test/Polly.Specs/Wrap/PolicyWrapSpecs.cs +++ b/test/Polly.Specs/Wrap/PolicyWrapSpecs.cs @@ -320,7 +320,7 @@ public void Wrapping_two_policies_using_static_wrap_strongly_typed_syntax_should { Policy retry = Policy.Handle().Retry(); Policy breaker = Policy.Handle().CircuitBreaker(1, TimeSpan.FromSeconds(10)); - Action config = () => Policy.Wrap(retry, breaker); + Action config = () => Policy.Wrap(retry, breaker); Should.NotThrow(config); } @@ -456,7 +456,7 @@ public void Outermost_policy_handling_exception_should_report_as_PolicyWrap_hand .CircuitBreaker(1, TimeSpan.Zero); PolicyWrap wrap = outerHandlingANE.Wrap(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => { throw new ArgumentNullException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => throw new ArgumentNullException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -474,7 +474,7 @@ public void Outermost_policy_not_handling_exception_even_if_inner_policies_do_sh .CircuitBreaker(1, TimeSpan.Zero); PolicyWrap wrap = outerHandlingANE.Wrap(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => { throw new DivideByZeroException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => throw new DivideByZeroException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -492,7 +492,7 @@ public void Outermost_generic_policy_handling_exception_should_report_as_PolicyW .CircuitBreaker(1, TimeSpan.Zero); PolicyWrap wrap = outerHandlingANE.Wrap(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => { throw new ArgumentNullException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => throw new ArgumentNullException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); @@ -511,7 +511,7 @@ public void Outermost_generic_policy_not_handling_exception_even_if_inner_polici .CircuitBreaker(1, TimeSpan.Zero); PolicyWrap wrap = outerHandlingANE.Wrap(innerHandlingDBZE); - PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => { throw new DivideByZeroException(); }); + PolicyResult executeAndCaptureResultOnPolicyWrap = wrap.ExecuteAndCapture(() => throw new DivideByZeroException()); executeAndCaptureResultOnPolicyWrap.Outcome.ShouldBe(OutcomeType.Failure); executeAndCaptureResultOnPolicyWrap.FinalException.ShouldBeOfType(); diff --git a/test/Polly.TestUtils/Polly.TestUtils.csproj b/test/Polly.TestUtils/Polly.TestUtils.csproj index b1a41cf4c38..60c0025dfa7 100644 --- a/test/Polly.TestUtils/Polly.TestUtils.csproj +++ b/test/Polly.TestUtils/Polly.TestUtils.csproj @@ -4,7 +4,6 @@ $(TargetFrameworks);net481 Library enable - $(NoWarn);SA1600;SA1204;CA1062 false false false diff --git a/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj b/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj index 5bd1053492c..2521693c764 100644 --- a/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj +++ b/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj @@ -5,7 +5,6 @@ Test enable 100 - $(NoWarn);SA1600;SA1204 [Polly.Testing]*