From d1df03bba1fcb95f3abb9305cb79f80ab7da7dcc Mon Sep 17 00:00:00 2001 From: nohwnd-bot Date: Fri, 11 Sep 2026 08:00:57 +0200 Subject: [PATCH 1/2] Replace broad DoNotParallelize with narrow ResourceLock in CrashDumpTests Microsoft.Testing.Extensions.UnitTests is parallelized with [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]. OnTestHostProcessExitedAsync_ProcessKilledByHangDump_DeletesSequenceFileAndDoesNotPublishArtifacts carried a class-wide-effective [DoNotParallelize] even though it touches exactly one process-wide resource: the AppDomain.CurrentDomain data slot "ProcessKilledByHangDump" read by CrashDumpProcessLifetimeHandler and written by HangDumpProcessLifetimeHandler. No other test in the project reads or writes that slot, so a method-level [ResourceLock] on this one test is sufficient and lets it run concurrently with the rest of the class again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../CrashDumpTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs index 9fc195a338..3636687132 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs @@ -21,6 +21,13 @@ namespace Microsoft.Testing.Extensions.UnitTests; [TestClass] public sealed class CrashDumpTests { + // AppDomain.CurrentDomain.GetData/SetData("ProcessKilledByHangDump") is a process-wide data slot + // (see CrashDumpProcessLifetimeHandler.OnTestHostProcessExitedAsync and + // HangDumpProcessLifetimeHandler.DumpTaking). Only the single test method below reads or writes it, + // so a method-level lock on that one test is enough to serialize it against itself without forcing + // the whole class to run sequentially. + private const string ProcessKilledByHangDumpAppDomainDataResource = "Microsoft.Testing.Extensions.CrashDump.ProcessKilledByHangDumpAppDomainData"; + [TestMethod] [DataRow("Mini")] [DataRow("Heap")] @@ -498,7 +505,7 @@ await handler.OnTestHostProcessExitedAsync( } [TestMethod] - [DoNotParallelize] + [ResourceLock(ProcessKilledByHangDumpAppDomainDataResource)] public async Task OnTestHostProcessExitedAsync_ProcessKilledByHangDump_DeletesSequenceFileAndDoesNotPublishArtifacts() { string sequenceFile = Path.GetTempFileName(); From a6cda676f97ff9d6023590d810363632848baa77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 11 Sep 2026 11:49:41 +0200 Subject: [PATCH 2/2] Fix ResourceLock reader coverage Cover indirect CrashDump handler readers with a shared read lock and upgrade the AppDomain-slot mutator to exclusive access. Require the refactoring workflow to trace production read sets and prove declaration coverage before removing DoNotParallelize. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../resource-lock-refactoring.lock.yml | 2 +- .../workflows/resource-lock-refactoring.md | 38 +++++++++++++++++-- .../CrashDumpTests.cs | 8 ++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/workflows/resource-lock-refactoring.lock.yml b/.github/workflows/resource-lock-refactoring.lock.yml index 70563bb600..86df49b276 100644 --- a/.github/workflows/resource-lock-refactoring.lock.yml +++ b/.github/workflows/resource-lock-refactoring.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"811225ccda44f11771a5b910122e182a3eb2769bde6185abb3fd0f6c70f9d4db","body_hash":"6c9317f7c34d81aeb6e82d0c62afd2a181874a437b9e23dafbe72fa8e1bd8910","compiler_version":"v0.86.2","strict":true,"agent_id":"copilot","detection_agent_id":"copilot","detection_agent_model":"detection","engine_versions":{"copilot":"1.0.79"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"811225ccda44f11771a5b910122e182a3eb2769bde6185abb3fd0f6c70f9d4db","body_hash":"1494805e99d0b02246f864347a59902a4f1ccbbae1cfd13d555980582fdfc7e9","compiler_version":"v0.86.2","strict":true,"agent_id":"copilot","detection_agent_id":"copilot","detection_agent_model":"detection","engine_versions":{"copilot":"1.0.79"}} # gh-aw-manifest: {"version":1,"secrets":["BACKPORT_MACHINE_USER_PAT","GH_AW_CI_TRIGGER_TOKEN","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN"],"actions":[{"repo":"actions/cache/restore","sha":"55cc8345863c7cc4c66a329aec7e433d2d1c52a9","version":"v6.1.0"},{"repo":"actions/cache/save","sha":"55cc8345863c7cc4c66a329aec7e433d2d1c52a9","version":"v6.1.0"},{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/download-artifact","sha":"3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c","version":"v8.0.1"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"v9.0.0"},{"repo":"actions/setup-node","sha":"820762786026740c76f36085b0efc47a31fe5020","version":"v7.0.0"},{"repo":"actions/upload-artifact","sha":"043fb46d1a93c77aae656e7c1c64a875d1fc6a0a","version":"v7.0.1"},{"repo":"github/gh-aw-actions/setup","sha":"6aab9e5b5c91c615506061f09bedd81a23babe3c","version":"v0.86.2"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.27.44","digest":"sha256:0d727725c737b58c7bdf51f640cffb928385ec46517e0917c7f1a02f1bada8b4","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.27.44@sha256:0d727725c737b58c7bdf51f640cffb928385ec46517e0917c7f1a02f1bada8b4"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.27.44","digest":"sha256:b50fbadba138f6e9aba94aca09711335c489bb3b15861220cb66f6092e042dc7","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.27.44@sha256:b50fbadba138f6e9aba94aca09711335c489bb3b15861220cb66f6092e042dc7"},{"image":"ghcr.io/github/gh-aw-firewall/cli-proxy:0.27.44","digest":"sha256:c064d15974f7c933ec7d3f7b4038f4fd203547b3154bdc821afd379144887eff","pinned_image":"ghcr.io/github/gh-aw-firewall/cli-proxy:0.27.44@sha256:c064d15974f7c933ec7d3f7b4038f4fd203547b3154bdc821afd379144887eff"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.27.44","digest":"sha256:83e48bbe12c634be8c228a576832fe45f66c529ac3659db92bddbcf2eeb6d627","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.27.44@sha256:83e48bbe12c634be8c228a576832fe45f66c529ac3659db92bddbcf2eeb6d627"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.4.9","digest":"sha256:e5a1569aeaf41820fa7bdee3e94468cae448133cdbf00119ad24f5b74db1ab9f","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.4.9@sha256:e5a1569aeaf41820fa7bdee3e94468cae448133cdbf00119ad24f5b74db1ab9f"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:0d9f1fb5fd6610c0ac1f5194a38e45a8a1e81f8a390d5142d8e4e6f26a4b3196","pinned_image":"ghcr.io/github/gh-aw-node@sha256:0d9f1fb5fd6610c0ac1f5194a38e45a8a1e81f8a390d5142d8e4e6f26a4b3196"},{"image":"ghcr.io/github/github-mcp-server:v1.9.0","digest":"sha256:881b53d6f75f69bdbc1b5b10fc2f1361717c19054143b3a8529fb5c32061a50e","pinned_image":"ghcr.io/github/github-mcp-server:v1.9.0@sha256:881b53d6f75f69bdbc1b5b10fc2f1361717c19054143b3a8529fb5c32061a50e"}]} # This file was automatically generated by gh-aw (v0.86.2). DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # diff --git a/.github/workflows/resource-lock-refactoring.md b/.github/workflows/resource-lock-refactoring.md index d315da854a..581086c66b 100644 --- a/.github/workflows/resource-lock-refactoring.md +++ b/.github/workflows/resource-lock-refactoring.md @@ -190,8 +190,20 @@ sample-input changes. ## Refactoring requirements -- Prove a concrete shared resource and a concurrently reachable observer or - mutator before adding a lock. Do not decorate tests speculatively. +- Prove a concrete shared resource and every concurrently reachable observer or + mutator before adding a lock. Do not decorate tests speculatively. Searching + test sources for the resource key is not proof of complete coverage: tests can + observe it indirectly through production methods that read the resource. +- Before replacing any `[DoNotParallelize]`, write a resource coverage matrix in + your working notes with these columns: resource, direct test writers, + production readers/writers, tests that invoke those production paths, and the + matching declaration that protects each test. Follow the call graph from the + candidate test into production code, then search the owning test project for + every call site of each production reader/writer. Every concurrently runnable + observer must either declare the same key (use + `Mode = ResourceAccessMode.Read` for readers), inherit a class-level lock, or + be isolated from the resource. If any row is unknown or uncovered, retain + `[DoNotParallelize]` and select another candidate or call `noop`. - Prefer eliminating shared state. Use `TestContext.TestTempDirectory` for per-test filesystem state when available, and use unique `TestAssetFixture`/test-asset identifiers when generated projects would @@ -223,6 +235,22 @@ sample-input changes. ## Validate the selected change +Before running tests, perform a declaration-reconciliation self-review using +category C of `.github/workflows/shared/parallel-safety-audit-shared.md`. Rebuild +the resource coverage matrix from the final diff and verify that: + +- the lock covers the production code's complete read/write set, not only the + API directly called by the changed test; +- every test in the owning assembly that can invoke a reader or writer declares + the same key with a compatible access mode; +- no correctness claim relies only on a literal-key grep; and +- if `[DoNotParallelize]` was removed, there is a concrete interleaving showing + why the replacement declarations prevent every previously excluded race. + +If this self-review finds an uncovered observer, fix the declarations or revert +the attempted replacement and call `noop`. A passing test run is not evidence +that a scheduling race is impossible. + Use the repository-pinned SDK and the smallest build and focused tests that cover the edited class or methods. Follow `.github/copilot-instructions.md` exactly: @@ -259,8 +287,10 @@ changes, then call `create_pull_request` exactly once with: - a title describing the concrete refactoring (the safe output adds the `[ResourceLock]` prefix) - a body that names the selected test project, its current parallelization - scope, the shared resource and conflicting tests, why the attribute placement - is minimal, every validation command with its result, and the workflow run URL + scope, the shared resource, every direct and indirect conflicting test from the + resource coverage matrix, why the attribute placement covers every observer + while remaining minimal, every validation command with its result, and the + workflow run URL - an explicit note when the project remains sequential that this is preparation for a later parallelization opt-in, not an opt-in itself diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs index 3636687132..b175000ca5 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CrashDumpTests.cs @@ -19,13 +19,13 @@ namespace Microsoft.Testing.Extensions.UnitTests; [TestClass] +[ResourceLock(ProcessKilledByHangDumpAppDomainDataResource, Mode = ResourceAccessMode.Read)] public sealed class CrashDumpTests { // AppDomain.CurrentDomain.GetData/SetData("ProcessKilledByHangDump") is a process-wide data slot - // (see CrashDumpProcessLifetimeHandler.OnTestHostProcessExitedAsync and - // HangDumpProcessLifetimeHandler.DumpTaking). Only the single test method below reads or writes it, - // so a method-level lock on that one test is enough to serialize it against itself without forcing - // the whole class to run sequentially. + // read by CrashDumpProcessLifetimeHandler.OnTestHostProcessExitedAsync. The class-level read lock + // lets its tests remain concurrent with each other, while the method-level read-write lock below + // excludes every indirect reader while that test mutates the slot. private const string ProcessKilledByHangDumpAppDomainDataResource = "Microsoft.Testing.Extensions.CrashDump.ProcessKilledByHangDumpAppDomainData"; [TestMethod]