-
Notifications
You must be signed in to change notification settings - Fork 275
Add analyzer to suggest using cooperative cancellation for timeout #5786
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
Conversation
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add the codefix related to this analyzer please.
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Added codefix for the UseCooperativeCancellationForTimeout analyzer. The codefix automatically transforms Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeout attribute can be also specified on all fixture methods (e.g. ClassInitialize
) so please remove the check for TestMethodAttribute
, checking only TimeoutAttribute
is enough. There is another rule to ensure the TimeoutAttribute
is used at the right location.
Please update codefixer and tests!
src/Analyzers/MSTest.Analyzers/UseCooperativeCancellationForTimeoutAnalyzer.cs
Outdated
Show resolved
Hide resolved
…d with Timeout attribute Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Removed the check for Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
This PR introduces a new analyzer
MSTEST0045
that warns users when they use[Timeout]
attribute without explicitly settingCooperativeCancellation = true
. This prepares users for a future breaking change where cooperative cancellation will become the default behavior.Problem
Currently, the
TimeoutAttribute
has aCooperativeCancellation
property that defaults tofalse
. In a future version (v5.0), cooperative cancellation will become the default behavior. To help users prepare for this breaking change, we need an analyzer that encourages them to explicitly opt into the recommended behavior.Solution
The new analyzer
UseCooperativeCancellationForTimeoutAnalyzer
detects:[Timeout]
attributes on test methods withoutCooperativeCancellation
specified[Timeout]
attributes withCooperativeCancellation = false
explicitly setAnd reports an Info-level diagnostic suggesting to use
CooperativeCancellation = true
.Examples
❌ Will trigger diagnostic:
✅ No diagnostic:
Implementation Details
MSTEST0045
[Timeout]
attributes on test methods ([TestMethod]
,[DataTestMethod]
, etc.)Files Added/Modified
UseCooperativeCancellationForTimeoutAnalyzer.cs
- Main analyzer implementationUseCooperativeCancellationForTimeoutAnalyzerTests.cs
- Comprehensive unit testsWellKnownTypeNames.cs
to includeTimeoutAttribute
DiagnosticIds.cs
withMSTEST0045
Test Coverage
The implementation includes comprehensive tests covering:
CooperativeCancellation = true
→ no diagnosticCooperativeCancellation = false
→ diagnosticTestMethod
,DataTestMethod
)TestTimeout
enum usage scenariosFixes #5761.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cflvsblobprodcus383.vsblob.vsassets.io
/home/REDACTED/work/testfx/testfx/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/testfx/testfx/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/testfx/testfx/artifacts/toolset/10.0.0-beta.25313.2.txt
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.