Repository navigation
[rel/4.5] Preserve global cleanup after local cancellation - #12220
Conversation
Backport e0ce525219a1e10bcce8d2b3ab048b03ac26b495 for #6157. Preserve independent global cleanup after local cancellation while retaining original failures, healthy token identity, active test/run cancellation budgets, and existing fail-fast rules. Validated on rel/4.5: 13/13 focused regressions, 121/121 lifecycle tests, and 8/8 packed net8 consumers, including source-generated metadata. The retained original implementation produced the intended 9/13 unit failures and 6/8 resource-release failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Scope: TestMethodInfo.Lifecycle.cs (cleanup cancellation isolation for global test cleanups), a new acceptance test, and new unit tests.
Summary: The logic isolates global cleanup from a locally cancelled token while still honoring the active test timeout and run cancellation. Referenced resources (TestCleanupWasCancelled, GlobalTestCleanupWasCancelled) already exist, so there are no localization or public API changes and no new dependencies.
Findings (non-blocking):
- Resource and registration lifecycle: the new
CancellationTokenSourceand the timeout-token registration are not disposed (see inline). - The new broad
catchchanges exception flow; confirm outcome mapping coverage (see inline). - The acceptance test includes an unasserted provenance dump (see inline).
Tests: Good scenario coverage (normal, error, cancel return/throw, timeout, global throw, source-gen). The acceptance test uses [DoNotParallelize] and a raw-string trace assertion, as the repo guidelines require. I did not run the tests; this review was done by static reading only.
A cooperative local
TestCleanuptimeout can cancel the token later reused byGlobalTestCleanup, skipping global teardown and leaking resources created by global initialization. This backports the narrow fix torel/4.5: renew a canceled cleanup source only at the local-to-global cleanup boundary while preserving the original failure and existing test/run cancellation budgets.This is non-breaking: no public/internal API additions, default-timeout changes, healthy-token-identity changes, or inherited/multiple-global fail-fast changes. The only cherry-pick conflict was a mechanical unit-test helper insertion; unrelated main-branch features were not copied.
Relates to #6157.
Backports commit
e0ce525219a1e10bcce8d2b3ab048b03ac26b495.Validation
Validated with repository-pinned SDK
12.0.100-alpha.1.26480.103, MSTest4.5.3-dev, and Microsoft.Testing.Platform2.5.3-dev. Thenet12.0outer acceptance host exercised real packednet8.0consumers, including source-generated metadata.--treenode-filter "/*/*/TestMethodInfoTests/GlobalCleanup*"--treenode-filter "/*/*/TestMethodInfoTests/*"--filter "FullyQualifiedName~CleanupCancellationIsolationTests"No cases were skipped. With only the production fix removed, the same tests produced 9 intended unit failures and 6 resource-release assertion failures, with the remaining controls passing. All 16 child adapter loads in each packaged phase were verified against that phase's release-built package hash, including two source-generated loads. The fixed consumers verified resource removal, exact child TRX identities/outcomes, lifecycle ordering, and preservation of the original local failure.
Final targeted shipping build and pack both passed with warnings treated as errors. Reproduction commands below shorten only the binlog destinations:
Classic UAP was excluded through
SkipUapTargetFramework=true; the other adapter TFMs built. The Arcade whole-repository package inventory audit did not pass for the intentionally partial package set and omitted UAP assets; this is not a claim that the full repository pack/audit passed. The final targeted build/pack and requested consumer tests passed.