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