From 0e2aede3c7426a70fe2baa28525d0768632839e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:21:03 +0100 Subject: [PATCH 1/2] Fix flaky test caused by non-empty stdout check when remote process is faster then test process. --- .../tests/ProcessTests.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs index 784804bd995034..8e8ddb6e4c6b37 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs @@ -250,14 +250,27 @@ public void SignalHandler_CanDisposeInHandler(PosixSignal signal) SendSignal(signal, remoteHandle.Process.Id); + bool expectEmptyStdout = true; + // https://github.com/dotnet/runtime/issues/125733 + // Mono prints running threads stack trace listings and does not quit on receiving SIGQUIT if (PlatformDetection.IsMonoRuntime && signal == PosixSignal.SIGQUIT && !PlatformDetection.IsWindows) { + // Quit it in alternative way SendSignal(PosixSignal.SIGTERM, remoteHandle.Process.Id); + + // Do not check for empty stdout afterwards. Depending on how quick process was, + // it may contains multiline thread stack traces listing from original SIGQUIT SendSignal. + expectEmptyStdout = false; } Assert.True(remoteHandle.Process.WaitForExit(WaitInMS)); - Assert.True(remoteHandle.Process.StandardOutput.EndOfStream); + + if (expectEmptyStdout) + { + Assert.True(remoteHandle.Process.StandardOutput.EndOfStream); + } + if (OperatingSystem.IsWindows()) { Assert.Equal(unchecked((int)0xC000013A), remoteHandle.Process.ExitCode); // STATUS_CONTROL_C_EXIT From a3c4d905e5d195d42e046ae1707236dd8b656f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=BD=C5=AFrek?= <188900745+mrek-msft@users.noreply.github.com> Date: Mon, 23 Mar 2026 16:50:59 +0100 Subject: [PATCH 2/2] Rework to do not send two signal in Mono case. --- .../tests/ProcessTests.cs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs index 8e8ddb6e4c6b37..545f6fb25f6de5 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs @@ -248,29 +248,21 @@ public void SignalHandler_CanDisposeInHandler(PosixSignal signal) AssertRemoteProcessStandardOutputLine(remoteHandle, PosixSignalHandlerStartedMessage, WaitInMS); AssertRemoteProcessStandardOutputLine(remoteHandle, PosixSignalHandlerDisposedMessage, WaitInMS); - SendSignal(signal, remoteHandle.Process.Id); - - bool expectEmptyStdout = true; - // https://github.com/dotnet/runtime/issues/125733 // Mono prints running threads stack trace listings and does not quit on receiving SIGQUIT if (PlatformDetection.IsMonoRuntime && signal == PosixSignal.SIGQUIT && !PlatformDetection.IsWindows) { - // Quit it in alternative way + // Terminate process using SIGTERM instead. SendSignal(PosixSignal.SIGTERM, remoteHandle.Process.Id); - - // Do not check for empty stdout afterwards. Depending on how quick process was, - // it may contains multiline thread stack traces listing from original SIGQUIT SendSignal. - expectEmptyStdout = false; } - - Assert.True(remoteHandle.Process.WaitForExit(WaitInMS)); - - if (expectEmptyStdout) + else { - Assert.True(remoteHandle.Process.StandardOutput.EndOfStream); + SendSignal(signal, remoteHandle.Process.Id); } + Assert.True(remoteHandle.Process.WaitForExit(WaitInMS)); + Assert.True(remoteHandle.Process.StandardOutput.EndOfStream); + if (OperatingSystem.IsWindows()) { Assert.Equal(unchecked((int)0xC000013A), remoteHandle.Process.ExitCode); // STATUS_CONTROL_C_EXIT