-
Notifications
You must be signed in to change notification settings - Fork 278
Add analyzer to flow TestContext.CancellationToken in tests #5941
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: Evangelink <[email protected]>
Co-authored-by: Evangelink <[email protected]>
Co-authored-by: Evangelink <[email protected]>
…lationToken analyzer Co-authored-by: Evangelink <[email protected]>
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.
Don't go with a list of known APIs, instead use a similar logic as in https://github.com/dotnet/roslyn-analyzers/blob/714a51c57430dab50b67e5b468016288f5f7b0bd/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Co-authored-by: Evangelink <[email protected]>
Replaced the hardcoded API list with dynamic overload detection logic similar to the referenced Roslyn analyzer. Removed the 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:
|
Replaced with #6126 |
Implements a new analyzer
FlowTestContextCancellationTokenAnalyzer
(MSTEST0047) that detects when async operations in tests should useTestContext.CancellationTokenSource.Token
for proper cooperative cancellation and timeout handling.What this analyzer detects
❌ Before (triggers MSTEST0047)
✅ After (code fix applied)
Features
Task.Delay()
,HttpClient
methods,Stream
operations,File
operations,DbCommand
methodsCancellationToken.None
anddefault(CancellationToken)
with proper TestContext tokenTestContext.CancellationTokenSource.Token
parameter or replaces existing problematic tokensBenefits
[Timeout]
attributes and can be canceled cooperativelyImplementation details
The analyzer follows the pattern established by existing MSTest analyzers and integrates seamlessly with the analyzer infrastructure.
Fixes #5878.
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:
7tjvsblobprodcus341.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)c78vsblobprodcus322.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)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.25353.1.txt
(dns block)dotnet build --verbosity minimal
(dns block)d0svsblobprodcus381.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)jd4vsblobprodcus366.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)l49vsblobprodcus358.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)uy6vsblobprodcus34.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)vb4vsblobprodcus33.vsblob.vsassets.io
dotnet build --verbosity minimal
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.