App-vNext / Polly

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
https://www.thepollyproject.org
BSD 3-Clause "New" or "Revised" License
13.28k stars 1.22k forks source link

Cleanup the `Polly` and `Polly.Specs` codebase #1290

Open martintmk opened 1 year ago

martintmk commented 1 year ago

In the #1287 we enabled a full set of analyzers for these projects. Many of the rules are currently suppressed in each respective csproj file with the <NoWarn> element.

We can enable these rules one-be-one and cleanup the codebase.

davidCett commented 11 months ago

Hi👋I would like to help with this issue

martincostello commented 11 months ago

@davidCett Thanks for volunteering! Feel free to open a pull request to tackle one of the disabled warnings. I suggest you tackle one or two per pull request to prevent the diffs getting too big to easily review.

martincostello commented 1 month ago

💡 Tips for future contributors working on this issue:

sukreshmanda commented 3 weeks ago

For the warnings xUnit1031, it says blocking calls should not be used in a test method. The below mentioned code uses Task.WaitAll which is a blocking action.

Example :

#pragma warning disable xUnit1031 // Do not use blocking task operations in test method

Task.WaitAll([firstExecution, secondExecution], testTimeoutToExposeDeadlocks).Should().BeTrue();

#pragma warning restore xUnit1031 // Do not use blocking task operations in test method

The essence of the above lines is to check if firstExecution and secondExecution tasks finishes before the specified timeout (testTimeoutToExposeDeadlocks). I want to confirm if the below mentioned non-blocking code can be a proper replacement for the above code.

var allTasksTask = Task.WhenAll(firstExecution, secondExecution);

var completedTask = await Task.WhenAny(allTasksTask, Task.Delay(testTimeoutToExposeDeadlocks));

(completedTask == allTasksTask).Should().BeTrue();
martincostello commented 3 weeks ago

If I remember correctly, these tests are specifically testing synchronous code paths, so the suppressions should be left in place.