Skip to content

Show currently running tests in dotnet test MTP output (#49712)#54486

Merged
Evangelink merged 3 commits into
mainfrom
dev/amauryleve/show-active-tests
Jun 1, 2026
Merged

Show currently running tests in dotnet test MTP output (#49712)#54486
Evangelink merged 3 commits into
mainfrom
dev/amauryleve/show-active-tests

Conversation

@Evangelink
Copy link
Copy Markdown
Member

@Evangelink Evangelink commented May 28, 2026

Fixes #49712.

What

Surfaces currently-running tests in the dotnet test output for projects using Microsoft.Testing.Platform (MTP). The SDK already has all of the rendering machinery for this (TestProgressState/TestNodeResultsState/AnsiTerminalTestProgressFrame — including the ... and X more trimming), but it was dead code because:

  1. The IPC protocol carried no test started event for MTP, only TestResultMessages.
  2. TerminalTestReporterOptions.ShowActiveTests was never set.

This PR addresses both.

Changes

  • New IPC messageTestInProgressMessages model + TLV serializer registered with id 10. Mirrors DiscoveredTestMessages.
  • Dispatch + handlerTestApplication.OnRequest dispatches the new message; TestApplicationHandler.OnTestInProgressReceived validates the execution id and forwards each item to the reporter.
  • ReporterTerminalTestReporter.TestInProgress now takes the same (assembly, tfm, arch, executionId, instanceId, uid, displayName) shape as TestCompleted.
  • StateTestNodeResultsState keys running tests by (instanceId, uid) instead of just uid, and tracks a completed set so a late in-progress notification can never resurrect a finished test. Retries (which get a new instanceId) are surfaced correctly.
  • Default-onShowActiveTests is enabled when AnsiMode == AnsiIfPossible and progress isn't suppressed (so it stays off in CI, --no-ansi, --no-progress, and LLM environments).

Back-compat

The named-pipe protocol is not versioned for this change because TLV with unknown-id skip is sufficient:

  • Old SDK + new MTPNamedPipeServer is constructed with skipUnknownMessages: true and TestApplication.OnRequest already returns VoidResponse for UnknownMessage, so the events are dropped silently.
  • New SDK + old MTP — old MTPs simply never send the message, so the running-tests panel stays empty (which is what users see today).

No protocol version bump is needed.

Producer-side gating (concern from @nohwnd)

@nohwnd flagged in #49712 that 12 parallel processes flooding test started events for fast tests would be noisy. Mitigations in this PR:

  • The existing per-assembly ... and X more trimming in TestNodeResultsState.GetRunningTasks already handles bursty cases.
  • The stale-add guard means stragglers that arrive after a test result don't pollute the panel.

The companion MTP-side PR is microsoft/testfx#8652, which actually emits the new TestInProgressMessages from DotnetTestDataConsumer on InProgressTestNodeStateProperty. A further producer-side slow-test threshold (e.g. only emit after N ms) could be added there as a follow-up.

Tests

  • TestInProgressMessagesSerializerTests — round-trip with populated and empty payloads; pins serializer id to 10.
  • TestNodeResultsStateTests — stale-add suppression after completion, retry path (new instanceId re-adds), distinct (instanceId, uid) keying.

All 6 new tests pass.

Adds a new TestInProgressMessages IPC message type (serializer id 10) so that the test platform can notify the SDK when a test starts. The SDK already has rendering machinery for in-progress tests (TestProgressState, TestNodeResultsState, AnsiTerminalTestProgressFrame, including the '... and X more' trimming) but it was dead because the protocol carried no 'test started' event and ShowActiveTests was never enabled.

Changes:

* IPC layer: new TestInProgressMessages model + TLV serializer, registered with id 10. Back-compat is preserved by the TLV format (unknown field ids are skipped) and NamedPipeServer skipUnknownMessages, so old SDKs paired with new MTPs continue to work and vice-versa.

* Handler: TestApplicationHandler.OnTestInProgressReceived forwards each event to TerminalTestReporter.TestInProgress(assembly, tfm, arch, executionId, instanceId, uid, displayName).

* State: TestNodeResultsState now keys running tests by (instanceId, uid) and tracks a completed set, so a stale in-progress notification arriving after the matching test result cannot resurrect a 'running' entry. Retries (new instanceId) are still surfaced correctly.

* Default-on: ShowActiveTests is enabled when AnsiMode == AnsiIfPossible and progress is not suppressed, so it stays off in CI, --no-ansi, --no-progress and LLM environments.

* Tests: round-trip + serializer id assertion for the new serializer, plus stale-add suppression / retry handling for TestNodeResultsState.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 28, 2026 10:36
@Evangelink Evangelink requested a review from a team as a code owner May 28, 2026 10:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables live display of currently running tests in dotnet test for Microsoft.Testing.Platform by adding an IPC message for in-progress tests and wiring it into the existing terminal progress renderer.

Changes:

  • Adds TestInProgressMessages IPC model, serializer, field IDs, and serializer registration.
  • Dispatches in-progress test events through TestApplicationHandler into TerminalTestReporter.
  • Updates active-test state tracking to key by (instanceId, uid) and adds tests for serializer and state behavior.
Show a summary per file
File Description
src/Cli/dotnet/Commands/Test/MTP/IPC/Models/TestInProgressMessages.cs Adds IPC records for running-test notifications.
src/Cli/dotnet/Commands/Test/MTP/IPC/ObjectFieldIds.cs Reserves field and serializer IDs for in-progress test messages.
src/Cli/dotnet/Commands/Test/MTP/IPC/Serializers/RegisterSerializers.cs Registers the new serializer.
src/Cli/dotnet/Commands/Test/MTP/IPC/Serializers/TestInProgressMessagesSerializer.cs Implements TLV serialization for in-progress test messages.
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Routes the new message type to the handler.
src/Cli/dotnet/Commands/Test/MTP/TestApplicationHandler.cs Validates and forwards running-test notifications to the reporter.
src/Cli/dotnet/Commands/Test/MTP/Terminal/TerminalTestReporter.cs Adds instance-aware active-test updates and removal.
src/Cli/dotnet/Commands/Test/MTP/Terminal/TestNodeResultsState.cs Tracks running tests by instance and suppresses stale completed entries.
src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs Enables active-test display for ANSI progress mode.
test/dotnet.Tests/CommandTests/Test/TestInProgressMessagesSerializerTests.cs Adds serializer round-trip and ID coverage.
test/dotnet.Tests/CommandTests/Test/TestNodeResultsStateTests.cs Adds coverage for stale-add suppression and retry keying.

Copilot's findings

  • Files reviewed: 11/11 changed files
  • Comments generated: 1

Evangelink and others added 2 commits May 29, 2026 08:50
…pability

The ShowActiveTests option is set based on the requested AnsiMode, but
TerminalTestReporter may decide at runtime to disable progress (e.g. when
stdout is redirected, console is non-TTY, or ANSI codes aren't accepted).
In that case the incoming TestInProgress events would still allocate and
update TestNodeResultsState even though nothing can ever be rendered.

Compute an effective _showActiveTests in the ctor as
_options.ShowActiveTests && showProgress and use it to gate both the
AddRunningTestNode and RemoveRunningTestNode paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink merged commit cf7f1ff into main Jun 1, 2026
25 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/show-active-tests branch June 1, 2026 09:21
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.

Improve output of dotnet test with MTP

3 participants