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
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions test/Polly.Specs/CircuitBreaker/AdvancedCircuitBreakerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions test/Polly.Specs/CircuitBreaker/CircuitBreakerTResultSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions test/Polly.Specs/Helpers/Bulkhead/AssertionFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/Polly.Specs/Helpers/Caching/StubErroringCacheProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion test/Polly.Specs/Polly.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
9 changes: 3 additions & 6 deletions test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
2 changes: 2 additions & 0 deletions test/Polly.Specs/Retry/WaitAndRetryForeverSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down
Loading