Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IDE0011 warning #2171

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs
Original file line number Diff line number Diff line change
@@ -78,7 +78,9 @@ protected BulkheadSpecsBase(ITestOutputHelper testOutputHelper)
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));
}

MaxParallelization = maxParallelization;
MaxQueuingActions = maxQueuingActions;
Original file line number Diff line number Diff line change
@@ -1602,9 +1602,15 @@ await breaker.ExecuteAsync(async () =>
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -1711,9 +1717,15 @@ await breaker.ExecuteAsync(async () =>
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -2030,7 +2042,10 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
if (longRunningExecution.IsFaulted)
{
throw longRunningExecution!.Exception!;
}

longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);

// onBreak() should still only have been called once.
12 changes: 12 additions & 0 deletions test/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs
Original file line number Diff line number Diff line change
@@ -1605,9 +1605,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method

if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -1717,9 +1723,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method

if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -454,9 +454,15 @@ await breaker.ExecuteAsync(async () =>
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -557,9 +563,15 @@ await breaker.ExecuteAsync(async () =>
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -822,7 +834,10 @@ await breaker.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
if (longRunningExecution.IsFaulted)
{
throw longRunningExecution!.Exception!;
}

longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);

// onBreak() should still only have been called once.
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs
Original file line number Diff line number Diff line change
@@ -450,9 +450,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -551,9 +557,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -813,7 +825,10 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
if (longRunningExecution.IsFaulted)
{
throw longRunningExecution!.Exception!;
}

longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);

// onBreak() should still only have been called once.
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -524,9 +524,15 @@ await breaker.ExecuteAsync(async () =>
#pragma warning restore xUnit1031

if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -635,9 +641,15 @@ await breaker.ExecuteAsync(async () =>
#pragma warning restore xUnit1031

if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -904,7 +916,10 @@ public async Task Should_call_onbreak_when_breaking_circuit_first_time_but_not_f
#pragma warning restore xUnit1031

if (longRunningExecution.IsFaulted)
{
throw longRunningExecution!.Exception!;
}

longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);

// onBreak() should still only have been called once.
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs
Original file line number Diff line number Diff line change
@@ -517,9 +517,15 @@ public void Should_only_allow_single_execution_on_first_entering_halfopen_state_
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -621,9 +627,15 @@ public void Should_allow_single_execution_per_break_duration_in_halfopen_state__
permitFirstExecutionEnd.Set();
Task.WaitAll(new[] { firstExecution, secondExecution }, testTimeoutToExposeDeadlocks).Should().BeTrue();
if (firstExecution.IsFaulted)
{
throw firstExecution!.Exception!;
}

if (secondExecution.IsFaulted)
{
throw secondExecution!.Exception!;
}

firstExecution.Status.Should().Be(TaskStatus.RanToCompletion);
secondExecution.Status.Should().Be(TaskStatus.RanToCompletion);

@@ -885,7 +897,10 @@ public void Should_call_onbreak_when_breaking_circuit_first_time_but_not_for_sub
// Graceful cleanup: allow executions time to end naturally; timeout if any deadlocks; expose any execution faults. This validates the test ran as expected (and background delegates are complete) before we assert on outcomes.
longRunningExecution.Wait(testTimeoutToExposeDeadlocks).Should().BeTrue();
if (longRunningExecution.IsFaulted)
{
throw longRunningExecution!.Exception!;
}

longRunningExecution.Status.Should().Be(TaskStatus.RanToCompletion);

// onBreak() should still only have been called once.
2 changes: 2 additions & 0 deletions test/Polly.Specs/Helpers/Bulkhead/AssertionFailure.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,9 @@ public class AssertionFailure
public AssertionFailure(int expected, int actual, string measure)
{
if (string.IsNullOrWhiteSpace(measure))
{
throw new ArgumentNullException(nameof(measure));
}

Expected = expected;
Actual = actual;
6 changes: 6 additions & 0 deletions test/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs
Original file line number Diff line number Diff line change
@@ -16,14 +16,20 @@ public StubErroringCacheProvider(Exception? getException, Exception? putExceptio
public (bool, object?) TryGet(string key)
{
if (_getException != null)
{
throw _getException;
}

return _innerProvider.TryGet(key);
}

public void Put(string key, object? value, Ttl ttl)
{
if (_putException != null)
{
throw _putException;
}

_innerProvider.Put(key, value, ttl);
}

Original file line number Diff line number Diff line change
@@ -5,15 +5,19 @@ internal static class AddBehaviourIfHandleSyntax
internal static AddBehaviourIfHandlePolicy WithBehaviour(this PolicyBuilder policyBuilder, Action<Exception> behaviourIfHandle)
{
if (behaviourIfHandle == null)
{
throw new ArgumentNullException(nameof(behaviourIfHandle));
}

return new AddBehaviourIfHandlePolicy(behaviourIfHandle, policyBuilder);
}

internal static AddBehaviourIfHandlePolicy<TResult> WithBehaviour<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>> behaviourIfHandle)
{
if (behaviourIfHandle == null)
{
throw new ArgumentNullException(nameof(behaviourIfHandle));
}

return new AddBehaviourIfHandlePolicy<TResult>(behaviourIfHandle, policyBuilder);
}
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ internal static AsyncAddBehaviourIfHandlePolicy WithBehaviourAsync(
Func<Exception, Task> behaviourIfHandle)
{
if (behaviourIfHandle == null)
{
throw new ArgumentNullException(nameof(behaviourIfHandle));
}

return new AsyncAddBehaviourIfHandlePolicy(behaviourIfHandle, policyBuilder);
}
@@ -17,7 +19,9 @@ internal static AsyncAddBehaviourIfHandlePolicy<TResult> WithBehaviourAsync<TRes
Func<DelegateResult<TResult>, Task> behaviourIfHandle)
{
if (behaviourIfHandle == null)
{
throw new ArgumentNullException(nameof(behaviourIfHandle));
}

return new AsyncAddBehaviourIfHandlePolicy<TResult>(behaviourIfHandle, policyBuilder);
}
1 change: 0 additions & 1 deletion test/Polly.Specs/Polly.Specs.csproj
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
<Include>[Polly]*</Include>
<IncludePollyUsings>true</IncludePollyUsings>
<NoWarn>$(NoWarn);CA1030;CA1031;CA2008;CA2201</NoWarn>
<NoWarn>$(NoWarn);IDE0011</NoWarn>
<NoWarn>$(NoWarn);S103;S104;S2184;S3878;S6966</NoWarn>
<NoWarn>$(NoWarn);SA1204;SA1402;SA1600;SA1649</NoWarn>
</PropertyGroup>
9 changes: 3 additions & 6 deletions test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -647,12 +647,9 @@ public async Task Should_be_able_to_calculate_retry_timespans_based_on_the_handl

using (var enumerator = expectedRetryWaits.GetEnumerator())
{
await policy.ExecuteAsync(() =>
{
if (enumerator.MoveNext())
throw enumerator.Current.Key;
return TaskHelper.EmptyTask;
});
await policy.ExecuteAsync(() => enumerator.MoveNext()
? throw enumerator.Current.Key
: TaskHelper.EmptyTask);
}

actualRetryWaits.Should().ContainInOrder(expectedRetryWaits.Values);
3 changes: 3 additions & 0 deletions test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs
Original file line number Diff line number Diff line change
@@ -385,7 +385,10 @@ public async Task Should_be_able_to_calculate_retry_timespans_based_on_the_handl
await policy.ExecuteAsync(() =>
{
if (enumerator.MoveNext())
{
throw enumerator.Current.Key;
}

return TaskHelper.EmptyTask;
});
}
2 changes: 2 additions & 0 deletions test/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs
Original file line number Diff line number Diff line change
@@ -309,7 +309,9 @@ public void Should_be_able_to_calculate_retry_timespans_based_on_the_handled_fau
policy.Execute(() =>
{
if (enumerator.MoveNext())
{
throw enumerator.Current.Key;
}
});
}

Original file line number Diff line number Diff line change
@@ -32,10 +32,9 @@ public async Task Should_be_able_to_calculate_retry_timespans_based_on_the_handl
await policy.ExecuteAsync(async () =>
{
await TaskHelper.EmptyTask;
if (enumerator.MoveNext())
return enumerator.Current.Key;
else
return ResultPrimitive.Undefined;
return enumerator.MoveNext()
? enumerator.Current.Key
: ResultPrimitive.Undefined;
});
}

Loading