Repository navigation
[ResourceLock] Remove unneeded [DoNotParallelize] from culture-mutation tests in TerminalTestReporterTests - #11229
Conversation
…minalTestReporterTests CultureInfo.CurrentCulture/CurrentUICulture mutations flow via ExecutionContext, which the thread pool captures/restores per Task.Run work item (MSTest's scheduling unit), so they cannot leak across concurrently scheduled sibling tests under this assembly's method-level parallelization. The TestNodeResultsState instances mutated in these two tests are private locals, not shared state, so no [ResourceLock] key is needed either -- matching the existing, reviewed rationale already applied to the same pattern in FfmpegVideoRecorderTests.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Correct the rationale comments to avoid the inaccurate scheduling guarantee.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Removes unnecessary [DoNotParallelize] attributes from two culture-mutation tests.
Changes:
- Enables method-level parallel execution for both tests.
- Retains local test state and culture restoration.
- Adds isolation rationale comments.
File summaries
| File | Summary |
|---|---|
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs |
Removes two parallelization exclusions; rationale comments should avoid claiming each test has a separate Task.Run work item. |
Review details
Suppressed comments (1)
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs:2170
- This duplicate rationale repeats the inaccurate claim that sibling tests are
Task.Run-scheduled work items. The runner schedules worker tasks, then runs multiple test methods sequentially inside each worker, so this comment should describe thefinallyrestoration and worker-level isolation instead of attributing safety to a per-testTask.Run.
// Same rationale as TestNodeResultsState_GetSingleActiveOrSummaryTask_WhenCultureChanges_ReformatsSummary
// above: CultureInfo.CurrentCulture/CurrentUICulture flow via ExecutionContext and cannot leak across
// the Task.Run-scheduled sibling tests that make up MSTest's method-level parallelization, and `state`
// is a private local instance, so no [ResourceLock]/[DoNotParallelize] is required here either.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Review comments request corrections to the execution-model rationale before approval.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (1)
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs:2165
- The scheduler creates one task per worker and each worker drains multiple test chunks; sibling test methods are not individually
Task.Run-scheduled. Please describe the worker-level ExecutionContext isolation instead, otherwise this rationale misstates the execution model it relies on.
// above: CultureInfo.CurrentCulture/CurrentUICulture flow via ExecutionContext and cannot leak across
// the Task.Run-scheduled sibling tests that make up MSTest's method-level parallelization, and `state`
// is a private local instance, so no [ResourceLock]/[DoNotParallelize] is required here either.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite (auto)
Note
Copilot is running an experiment and ran this review at Lite.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The tests use local state, restore ambient culture in finally, and MSTest worker execution provides the claimed isolation.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Balanced
gh-aw-workflow-id: resource-lock-refactoring
Project and scope
test/UnitTests/Microsoft.Testing.Platform.UnitTests(Microsoft.Testing.Platform.UnitTests.csproj). The assembly is already parallelized:[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]inProgram.cs. This PR does not change that attribute or any other assembly-level parallelization/.runsettings/testconfig.jsonsetting — it only removes two unnecessary method-level[DoNotParallelize]attributes that were narrower than the truth: the resource they guarded against was never actually process-global.The change
In
OutputDevice/Terminal/TerminalTestReporterTests.cs, removed[DoNotParallelize]from:TestNodeResultsState_GetSingleActiveOrSummaryTask_WhenCultureChanges_ReformatsSummaryTestNodeResultsState_GetRunningTasks_WhenCultureChanges_ReformatsSummaryBoth tests mutate
CultureInfo.CurrentCulture/CultureInfo.CurrentUICultureinside atry/finallythat restores the original values, against aTestNodeResultsStateinstance that is a private local variable created inside the test method — never shared across tests.Resource coverage matrix
CultureInfo.CurrentCulture/CurrentUICulture(thread-local, ExecutionContext-scoped)finally)TestNodeResultsState.GetFullTestsCountText/GetMoreTestsCountText(src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TestNodeResultsState.cs) readCultureInfo.CurrentCulture/CurrentUICultureto format and cache summary textTestNodeResultsState_*test in the same file reads/formats through the same production methods, but each constructs its own privateTestNodeResultsStateinstance and runs with whatever ambient culture its own thread has — it never observes a culture mutated by a sibling testCultureInfo.CurrentCulture/CurrentUICulturesetters write to the current thread'sExecutionContext, and the .NETThreadPoolcaptures/restoresExecutionContextper queued work item. MSTest schedules every test method throughTask.Run(seeTestExecutionManager,TestMethodInfo.Lifecycle, confirmed viagrep -rl "Task.Run" src/Adapter), so a culture mutation performed inside one test'sTask.Runwork item is invisible to every concurrently scheduled sibling test's own work item. There is no other shared resource:stateis anew TestNodeResultsState(1)local, not a static/shared field.I also verified empirically (outside the repo, as a throwaway console app) that mutating
CultureInfo.CurrentCultureinside one of 20 concurrentTask.Runwork items never becomes visible to any other concurrently runningTask.Runwork item, confirming the ExecutionContext isolation claim above.This exact rationale (culture flows via ExecutionContext and cannot leak across
Task.Run-scheduled MSTest tests) is already established and reviewed in this repository attest/UnitTests/Microsoft.Testing.Extensions.UnitTests/FfmpegVideoRecorderTests.cs(see the comment aboveReadSegments_RelativeEntry_CombinesDirectoryAndParsesInvariantNumbers), which mutatesCultureInfo.CurrentCulturewith no[ResourceLock]/[DoNotParallelize]at all under the same kind of method-level-parallel assembly. This PR applies the identical, already-accepted reasoning to the two remaining un-annotated occurrences of the pattern inMicrosoft.Testing.Platform.UnitTests.Declaration-reconciliation self-review (category C)
TestNodeResultsState's two culture-aware formatting methods are the only production code that readsCultureInfo.CurrentCulture/CurrentUICulturein a way reachable from these tests, and both are exercised only through each test's own privateTestNodeResultsStateinstance.[ResourceLock]key at all, because the underlying mechanism (ExecutionContext capture/restore perTask.Runwork item) already isolates the mutation, independent of scheduling order or interleaving.Task.Run.Task.Runwork item), T1'sCultureInfo.CurrentCulture = Xassignment updates only theExecutionContextflowing through T1's own work item/continuations. T2's work item captured a separateExecutionContextwhen it was queued, soCultureInfo.CurrentCultureobserved inside T2 is unaffected by T1's assignment regardless of timing. This holds whether T2 starts before, during, or after T1's mutation.Validation
bash ./build.sh— full repo build succeeded (0 errors).PATH="$PWD/.dotnet:$PATH" dotnet build test/UnitTests/Microsoft.Testing.Platform.UnitTests -f net8.0 -c Debug— succeeded, 0 errors.PATH="$PWD/.dotnet:$PATH" dotnet run --project test/UnitTests/Microsoft.Testing.Platform.UnitTests -f net8.0 --no-build -c Debug -- --filter "FullyQualifiedName~TerminalTestReporterTests"— run 4 times in a row to probe for scheduling-order flakiness: 184/184 passed every time, 0 failed.PATH="$PWD/.dotnet:$PATH" dotnet run --project test/UnitTests/Microsoft.Testing.Platform.UnitTests -f net8.0 --no-build -c Debug(full project suite, method-level parallel) — 2541 succeeded, 21 skipped (pre-existing, unrelated), 0 failed.DOTNET_CLI_TELEMETRY_SESSIONIDwas left untouched/inherited by these commands (not explicitly overridden).Acceptance/integration tests were not run for this change: it touches only a unit-test file with no product-code or packaging impact, so
-packwas not required or attempted.Notes
MethodLevel,Workers = 0); this PR is not an opt-in to parallelization, it narrows an already-parallel project's over-broad[DoNotParallelize]usage per option 1 of the refactoring priorities.Parallelize/DoNotParallelizeattribute,.runsettings, ortestconfig.jsonparallelization setting was added or changed.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
southcentralus0.in.applicationinsights.azure.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.