Skip to content

[rel/4.5] Preserve global cleanup after local cancellation - #12220

Merged
Amaury Levé (Evangelink) merged 1 commit into
rel/4.5from
dev/amauryleve/cleanup-isolation-backport
Nov 5, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
rel/4.5from
dev/amauryleve/cleanup-isolation-backport

Conversation

@Evangelink

Copy link
Copy Markdown
Member

A cooperative local TestCleanup timeout can cancel the token later reused by GlobalTestCleanup, skipping global teardown and leaking resources created by global initialization. This backports the narrow fix to rel/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, MSTest 4.5.3-dev, and Microsoft.Testing.Platform 2.5.3-dev. The net12.0 outer acceptance host exercised real packed net8.0 consumers, including source-generated metadata.

Scope Selector Result
Focused regressions --treenode-filter "/*/*/TestMethodInfoTests/GlobalCleanup*" 13/13 passed; exit 0
Full release lifecycle class --treenode-filter "/*/*/TestMethodInfoTests/*" 121/121 passed; exit 0
Packed consumers --filter "FullyQualifiedName~CleanupCancellationIsolationTests" 8/8 passed; exit 0

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:

.\.dotnet\dotnet.exe build .\src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj --no-restore -c Debug -p:SkipUapTargetFramework=true -p:TreatWarningsAsErrors=true -p:MSBuildTreatWarningsAsErrors=true -m:4 -bl:rel45-green-targeted-build-20261105T113024004Z.binlog
.\.dotnet\dotnet.exe pack .\src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj --no-build --no-restore -c Debug -p:SkipUapTargetFramework=true -p:TreatWarningsAsErrors=true -p:MSBuildTreatWarningsAsErrors=true -m:4 -bl:rel45-green-targeted-pack-20261105T113024004Z.binlog

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.

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>
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Nov 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CancellationTokenSource and the timeout-token registration are not disposed (see inline).
  • The new broad catch changes 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.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 5, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 5, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 5, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Nov 5, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 5, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 5, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit 72fd2b4 into rel/4.5 Nov 5, 2026
48 of 49 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/cleanup-isolation-backport branch November 5, 2026 14:10
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants