Skip to content

[ResourceLock] Replace class-level DoNotParallelize with ResourceLock(Console) in TerminalOutputDeviceTests - #10790

Draft
nohwnd-bot wants to merge 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/terminal-output-device-tests-9632018be76f24c5
Draft

[ResourceLock] Replace class-level DoNotParallelize with ResourceLock(Console) in TerminalOutputDeviceTests#10790
nohwnd-bot wants to merge 1 commit into
microsoft:mainfrom
nohwnd-bot:resource-lock/terminal-output-device-tests-9632018be76f24c5

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

gh-aw-workflow-id: resource-lock-refactoring

Summary

Replaces the class-level [DoNotParallelize] on TerminalOutputDeviceTests
(test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/TerminalOutputDeviceTests.cs)
with [ResourceLock(WellKnownResources.Console)].

Project and current scope: Microsoft.Testing.Platform.UnitTests already
declares [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]
in Program.cs, so this project is already parallelized at the method level.
TerminalOutputDeviceTests was one of the few classes still opting out entirely
via a class-level [DoNotParallelize].

Shared resource and conflicting tests: every test method in the class
temporarily redirects the process-global Console.Error stream
(Console.SetError(...)) to capture output, then restores the original writer
in a finally block. Six methods in the class do this
(AssertListTestsJsonStandardErrorAsync / CaptureListTestsJsonStandardErrorAsync
and InitializeAndCaptureStandardErrorAsync, used by 8+ [TestMethod]s). Since
Console.Error is process-global, two tests in this class running concurrently
under MethodLevel parallelization could redirect/restore the stream out of
order and corrupt each other's captured output. The class previously guarded
this with a hand-rolled SemaphoreSlim ConsoleErrorSemaphore plus
[DoNotParallelize] at the class level — a strictly broader mechanism than
needed, since it serializes the whole class rather than just the
Console.Error critical sections.

Why this attribute placement is minimal: [ResourceLock(WellKnownResources.Console)]
at the class level lets the MSTest engine serialize only tests contending on the
same declared resource (System.Console), instead of forcing full sequential
execution of the class via [DoNotParallelize]. This is the narrowest
class-level fix because every test method in the class touches Console.Error,
so a method-level placement would be equivalent but more verbose; there is no
test in the class that doesn't need the lock. The now-redundant
ConsoleErrorSemaphore field and its WaitAsync/Release calls were removed
since [ResourceLock] already provides the serialization guarantee at the
MSTest engine level.

No assembly-level Parallelize/DoNotParallelize attributes, .runsettings,
or testconfig.json parallelization settings were touched.

Validation

  • bash ./build.sh — build succeeded (0 errors, 0 warnings).
  • PATH="$PWD/.dotnet:$PATH" dotnet run --project test/UnitTests/Microsoft.Testing.Platform.UnitTests -f net9.0 --no-build -c Debug -- --filter "FullyQualifiedName~TerminalOutputDeviceTests" — 10/10 tests passed under the assembly's actual MethodLevel parallel scheduling (Test Parallelization enabled ... Workers: 4, Scope: MethodLevel).
  • Acceptance/integration validation (./build.sh -pack) was not run: this change only touches a unit-test project and does not affect any acceptance test asset or packed artifact.

Workflow run: https://github.com/microsoft/testfx/actions/runs/33050722434

DOTNET_CLI_TELEMETRY_SESSIONID used during validation: gha-65080725-33050722434-1.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • southcentralus0.in.applicationinsights.azure.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "southcentralus0.in.applicationinsights.azure.com"

See Network Configuration for more information.

Automated by the ResourceLock refactoring workflow. · auto · 166.6 AIC · ⌖ 2.98 AIC · ⊞ 11.1K | [History]( · )

…rminalOutputDeviceTests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 27, 2026 07:56

Copilot AI 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.

Pull request overview

Replaces broad test-class serialization with resource-specific locking for process-global console access.

Changes:

  • Adds [ResourceLock(WellKnownResources.Console)].
  • Removes the redundant SemaphoreSlim and manual lock handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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