Fix xUnit1051: pass TestContext.Current.CancellationToken to async methods#53516
Closed
MichaelSimons wants to merge 19 commits intodotnet:mainfrom
Closed
Fix xUnit1051: pass TestContext.Current.CancellationToken to async methods#53516MichaelSimons wants to merge 19 commits intodotnet:mainfrom
MichaelSimons wants to merge 19 commits intodotnet:mainfrom
Conversation
Switch all ~55 test projects from xUnit v2 (2.9.3) to xUnit v3 (3.1.0) using the arcade SDK's built-in XUnitV3.targets support. Key changes: - Enable TestRunnerName=XUnitV3 in test/Directory.Build.props - Switch from Microsoft.DotNet.XUnitExtensions to XUnitV3Extensions - Upgrade Xunit.Combinatorial 1.3.2 -> 2.0.24 (v3-compatible) - Switch Verify.Xunit -> Verify.XunitV3 - Rewrite test entry point (Program.cs) as ModuleInitializer - Update ITestOutputHelper implementations (new Write/Output members) - Fix IMessageSink namespace (Xunit.Abstractions -> Xunit.Sdk) - Fix DiagnosticMessage namespace (Xunit.Sdk -> Xunit.v3) - Add CallerFilePath/CallerLineNumber ctors for custom attributes (xUnit3003) - Rewrite dotnet-format custom discoverers using IBeforeAfterTestAttribute - Exclude transitive v2 assemblies that conflict with v3 types - Add TestContext alias to resolve Xunit.TestContext ambiguity - Use xunit.v3.assert for non-test projects (SDDLTests) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…eues xUnit v3 runs tests out-of-process via a native AppHost, so when cross-compiling (e.g. ARM64 macOS build targeting x64 Helix queues) the publish step must set RuntimeIdentifier to produce the correct AppHost architecture. In CI, Arcade's centralized NuGet restore (via NuGet.targets) does not include RuntimeIdentifier, so the assets file lacks the RID target. An explicit Restore with RuntimeIdentifiers (plural) is added before PublishWithOutput to inject the RID target without clobbering multi-TFM transitive dependencies (e.g. BrowserRefresh which targets net6.0). ErrorOnDuplicatePublishOutputFiles=false suppresses NETSDK1152 from Exe project-references (e.g. dotnet.csproj) whose outputs appear in both the plain-TFM and RID-qualified directories. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…etPackageAdd WarmUpNuGetCache: check exit code, add timeout handling, and verify ILLink analyzer DLLs exist after warm-up so failures are surfaced instead of silently causing CSC-only assertion failures. GivenDotnetPackageAdd file-based tests: use RestoreAdditionalProjectSources instead of RestoreSources to add local package paths without replacing NuGet.config feeds. With xUnit v3 hash-based ordering, the NuGet cache may not be pre-populated when these tests run. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… dependency Both tests created a tool named MyFileBasedTool v1.0.0 with different source. With xUnit v3 hash-based ordering, Pack_CustomPath runs first and installs the tool; Pack then reuses the cached install instead of its own nupkg, missing the #if !DEBUG output. Rename to PackTool and PackCustomPathTool respectively. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WarmUpNuGetCache was using raw Process.Start which did not set the NUGET_PACKAGES environment variable that DotnetCommand sets via AddTestEnvironmentVariables. This caused packages to be restored to the default NuGet cache (~/.nuget/packages) while the actual tests resolved to the artifacts cache, so the ILLink analyzer DLLs were not found and GetBuildLevel() fell back to BuildLevel.All.
In xUnit v3, tests run out-of-process in a separate AppHost. When ItTerminatesWinExeAppWithCloseMainWindow calls GenerateConsoleCtrlEvent with dwProcessGroupId=0, the CTRL_C signal is sent to all processes sharing the console — including the xUnit v3 test host and the dotnet test process, crashing the entire test run. Fix by launching the dotnet run child process in a new process group via ProcessStartInfo.CreateNewProcessGroup. This isolates the child so that GenerateConsoleCtrlEvent(0, pid) targets only the child's group and does not propagate to the test host. This is the same pattern used by dotnet-watch (ProcessRunner.cs). Add CreateNewProcessGroup property to TestCommand/SdkCommandSpec so other tests that send console signals can use the same mechanism. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…thods Replace CancellationToken.None, default, and bare async calls with TestContext.Current.CancellationToken across all test projects so that test cancellation is responsive to the xUnit v3 runner. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
Superseded by #53714. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is WIP as it depends on #52930