Skip to content

Commit 76a93a5

Browse files
Zombachmartincostello
andauthoredJul 13, 2024··
Fix S103 (#2196)
Co-authored-by: Martin Costello <martin@martincostello.com>
1 parent 06b39ff commit 76a93a5

7 files changed

+15
-7
lines changed
 

‎test/Polly.Specs/Helpers/Bulkhead/TraceableAction.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public Task ExecuteOnBulkhead<TResult>(BulkheadPolicy<TResult?> bulkhead) =>
5151
return default;
5252
}, _cancellationSource.Token));
5353

54-
// Note re TaskCreationOptions.LongRunning: Testing the parallelization of the bulkhead policy efficiently requires the ability to start large numbers of parallel tasks in a short space of time. The ThreadPool's algorithm of only injecting extra threads (when necessary) at a rate of two-per-second however makes high-volume tests using the ThreadPool both slow and flaky. For PCL tests further, ThreadPool.SetMinThreads(...) is not available, to mitigate this. Using TaskCreationOptions.LongRunning allows us to force tasks to be started near-instantly on non-ThreadPool threads.
54+
// Note re TaskCreationOptions.LongRunning: Testing the parallelization of the bulkhead policy efficiently requires the ability to start large numbers of parallel tasks in a short space of time.
55+
// The ThreadPool's algorithm of only injecting extra threads (when necessary) at a rate of two-per-second however makes high-volume tests using the ThreadPool both slow and flaky.
56+
// For PCL tests further, ThreadPool.SetMinThreads(...) is not available, to mitigate this.
57+
// Using TaskCreationOptions.LongRunning allows us to force tasks to be started near-instantly on non-ThreadPool threads.
5558
private Task ExecuteThroughSyncBulkheadOuter(Action executeThroughBulkheadInner)
5659
{
5760
if (Status != TraceableActionStatus.Unstarted)

‎test/Polly.Specs/Polly.Specs.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Include>[Polly]*</Include>
1010
<IncludePollyUsings>true</IncludePollyUsings>
1111
<NoWarn>$(NoWarn);CA1030;CA1031;CA2008;CA2201</NoWarn>
12-
<NoWarn>$(NoWarn);S103;S104;S2184;S6966</NoWarn>
12+
<NoWarn>$(NoWarn);S104;S2184;S6966</NoWarn>
1313
<NoWarn>$(NoWarn);SA1204;SA1402;SA1600</NoWarn>
1414
</PropertyGroup>
1515

‎test/Polly.Specs/Retry/RetryAsyncSpecs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ await policy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
371371
public async Task Should_wait_asynchronously_for_async_onretry_delegate()
372372
{
373373
// This test relates to https://github.com/App-vNext/Polly/issues/107.
374-
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning to Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
374+
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively.
375+
// However, if it compiles to async void (assigning to Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
375376
// If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' of the retry policy would/could occur before onRetry execution had completed.
376377
// This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences.
377378

‎test/Polly.Specs/Retry/RetryForeverAsyncSpecs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ await policy.Awaiting(x => x.RaiseExceptionAsync<ArgumentException>())
240240
public async Task Should_wait_asynchronously_for_async_onretry_delegate()
241241
{
242242
// This test relates to https://github.com/App-vNext/Polly/issues/107.
243-
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
243+
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively.
244+
// However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
244245
// If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' would/could occur before onRetry execution had completed.
245246
// This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences.
246247

‎test/Polly.Specs/Retry/RetryTResultSpecsAsync.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ public async Task Should_not_call_onretry_when_retry_count_is_zero_with_context(
407407
public async Task Should_wait_asynchronously_for_async_onretry_delegate()
408408
{
409409
// This test relates to https://github.com/App-vNext/Polly/issues/107.
410-
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
410+
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively.
411+
// However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
411412
// If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' would/could occur before onRetry execution had completed.
412413
// This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences.
413414

‎test/Polly.Specs/Retry/WaitAndRetryAsyncSpecs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ await policy.Awaiting(x => x.RaiseExceptionAsync<DivideByZeroException>())
708708
public async Task Should_wait_asynchronously_for_async_onretry_delegate()
709709
{
710710
// This test relates to https://github.com/App-vNext/Polly/issues/107.
711-
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
711+
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively.
712+
// However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
712713
// If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' would/could occur before onRetry execution had completed.
713714
// This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences.
714715

‎test/Polly.Specs/Retry/WaitAndRetryForeverAsyncSpecs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ await policy.ExecuteAsync(async (context, _) =>
432432
public async Task Should_wait_asynchronously_for_async_onretry_delegate()
433433
{
434434
// This test relates to https://github.com/App-vNext/Polly/issues/107.
435-
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively. However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
435+
// An async (...) => { ... } anonymous delegate with no return type may compile to either an async void or an async Task method; which assign to an Action<...> or Func<..., Task> respectively.
436+
// However, if it compiles to async void (assigning tp Action<...>), then the delegate, when run, will return at the first await, and execution continues without waiting for the Action to complete, as described by Stephen Toub: https://devblogs.microsoft.com/pfxteam/potential-pitfalls-to-avoid-when-passing-around-async-lambdas/
436437
// If Polly were to declare only an Action<...> delegate for onRetry - but users declared async () => { } onRetry delegates - the compiler would happily assign them to the Action<...>, but the next 'try' would/could occur before onRetry execution had completed.
437438
// This test ensures the relevant retry policy does have a Func<..., Task> form for onRetry, and that it is awaited before the next try commences.
438439

0 commit comments

Comments
 (0)
Please sign in to comment.