Skip to content

Fix dotnet test hang when the test app process exits but a child process of it remains alive#52558

Merged
Evangelink merged 12 commits intomainfrom
dev/ygerges/child-process-mtp
Feb 11, 2026
Merged

Fix dotnet test hang when the test app process exits but a child process of it remains alive#52558
Evangelink merged 12 commits intomainfrom
dev/ygerges/child-process-mtp

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Jan 19, 2026

Fixes #51507

@Youssef1313 Youssef1313 marked this pull request as ready for review February 10, 2026 21:53
@Youssef1313 Youssef1313 requested a review from a team as a code owner February 10, 2026 21:53
Copilot AI review requested due to automatic review settings February 10, 2026 21:53
Copy link
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 adds a test case and implementation changes to prevent dotnet test from hanging when a test application exits but leaves a child process alive that has inherited stdout/stderr handles. The fix modifies the Microsoft Testing Platform (MTP) test runner to wait for process exit independently of consuming stdout/stderr, with a 5-second timeout for output consumption after the process has exited.

Changes:

  • Modified TestApplication.RunAsync to wait for process exit before reading stdout/stderr, with a 5-second timeout to handle orphaned child processes
  • Added WaitForExitWithoutOutputAsync helper method that waits for process exit without blocking on output streams
  • Added MTPChildProcessHangTest test project that simulates a test app spawning a hanging child process
  • Added a skipped test case to verify the fix (skipped because test infrastructure itself has the same issue)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Changed stdout/stderr reading to use line-based reading with StringBuilder, implemented WaitForExitWithoutOutputAsync, and added 5-second timeout after process exit
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs Added skipped test case for MTP child process hang scenario
test/TestAssets/TestProjects/MTPChildProcessHangTest/MTPChildProcessHangTest.csproj Test project configuration for hanging child process scenario
test/TestAssets/TestProjects/MTPChildProcessHangTest/global.json Configures test to use Microsoft.Testing.Platform runner
test/TestAssets/TestProjects/MTPChildProcessHangTest/Program.cs Test implementation that spawns a hanging child process during test execution

@Youssef1313 Youssef1313 changed the title Add test for hanging child process for MTP Fix dotnet test hang when the test app process exits but a child process of it remains alive Feb 11, 2026
@Evangelink Evangelink enabled auto-merge February 11, 2026 17:59
@Evangelink Evangelink merged commit 64f46da into main Feb 11, 2026
28 checks passed
@Evangelink Evangelink deleted the dev/ygerges/child-process-mtp branch February 11, 2026 23:21
@Youssef1313
Copy link
Member Author

/backport to release/10.0.3xx

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Started backporting to release/10.0.3xx (link to workflow run)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MTP][dotnet test] Add test for a test app that starts a child process where the child process doesn't terminate

3 participants