Repository navigation
Fix flaky MainWindow tests by replacing notepad.exe with a deterministic RemoteExecutor helper - #125907
Conversation
…or+MessageBoxW helper Co-authored-by: danmoseley <[email protected]> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/774170c7-e423-44bb-89d3-3c9ff3eb5b10
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
There was a problem hiding this comment.
Pull request overview
This PR addresses flakiness in System.Diagnostics.Process Windows GUI tests caused by Windows 11 Notepad returning a launcher/stub PID that doesn’t own the main window, breaking MainWindowFinder’s PID-to-window matching.
Changes:
- Removed the two Notepad-based
MainWindowHandle/MainWindowTitlerefresh tests fromProcessTests.cs. - Reintroduced the tests in
ProcessTests.Windows.csusing a deterministicRemoteExecutorchild process that shows aMessageBoxWwith a known caption.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs | Removes the Notepad-dependent GUI tests that are unreliable on Windows 11 due to alias/stub PID behavior. |
| src/libraries/System.Diagnostics.Process/tests/ProcessTests.Windows.cs | Adds a deterministic RemoteExecutor + MessageBoxW helper and rewrites the GUI refresh tests to target a controlled PID/window pair. |
|
@copilot address feedback |
Both test methods now use |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot it's the right direction but please address my feedback before we move forward
|
@copilot is all feedback adddressed if so resolve it |
Yes, all feedback has been addressed in fb68fb2. All four @adamsitnik threads are resolved — the tests are merged into one fact, stdout-based synchronization replaces polling, the child blocks until killed, and the title assertion is exact. |
|
@adamsitnik mergeable? |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
…eProcess + await Co-authored-by: adamsitnik <[email protected]> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/40c9076a-de1c-4d0a-b98e-84e456e1d0e0
|
/azp list |
|
/azp run runtime-libraries-coreclr outerloop-windows |
|
Azure Pipelines successfully started running 1 pipeline(s). |
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM the outerloop windows tests for process are going to be green.
Thank you @danmoseley !
|
/ba-g _cffi_backend' i already opened issue for |
main PR
Description
Windows 11's modern Notepad uses an App Execution Alias:
Process.Start("notepad.exe")returns a stub launcher PID, not the PID that owns the Notepad window.MainWindowFinderusesEnumWindows+GetWindowThreadProcessIdto match windows to the target PID — so it always returnsIntPtr.Zerofor the stub, regardless of retries.Fix: Replace the notepad dependency with a
RemoteExecutorchild process that callsMessageBoxW(IntPtr.Zero, ...)on a background thread, creating a visible, owner-less top-level window on a controlled PID. This satisfies bothMainWindowFinder.IsMainWindowcriteria (GetWindow(GW_OWNER) == NULLandIsWindowVisible), and the window title ("Test Main Window") makesMainWindowTitlenon-empty.ProcessTests.cs— removed both failing test methodsProcessTests.Windows.cs— added:IsNotNanoServerNotServerCoreAndRemoteExecutorSupportedcombined condition (preserves existing GUI guards, addsRemoteExecutor.IsSupported)CreateMainWindowWithTitle()static helper: showsMessageBoxWon a background thread (with an explanatory comment noting thatMessageBoxWblocks the calling thread), usesFindWindowWto spin-poll until the window is visible, writes"ready"to stdout, then blocks onThread.Sleep(Timeout.Infinite)until killed by the parent — no race condition[ConditionalFact]MainWindowHandle_And_Title_GetWithGui_ShouldRefresh_Windows(declaredasync Task) that checks bothMainWindowHandleandMainWindowTitlein one pass, reducing sequential test run timeCreateProcess(CreateMainWindowWithTitle)fromProcessTestBase(which callsAddProcessForDisposeinternally) and setsRedirectStandardOutput = truebefore callingprocess.Start(); waits once viaawait process.StandardOutput.ReadLineAsync(), performs oneRefresh(), then assertsMainWindowHandle != IntPtr.ZeroandAssert.Equal("Test Main Window", MainWindowTitle)— no retry polling loop, no manual handle-steal patternCustomer Impact
Tests fail consistently (~daily) on every CI run targeting full Windows editions. No production code change; test-only impact.
Regression
Not a regression in production code. The test began failing when Windows 11 shipped the new Notepad with App Execution Alias support.
Testing
The new helper is fully deterministic: the child signals the parent only after
FindWindowWconfirms the window is visible, eliminating the previous polling race. The parent awaits that signal once (no retry loop), performs a singleRefresh(), and asserts bothMainWindowHandleandMainWindowTitlein one merged async fact. The process is killed explicitly and cleaned up viaAddProcessForDispose.Risk
Low. Test-only change. No production code modified. The approach is consistent with existing patterns in the test suite (stdout-based synchronization mirrors the signal tests;
CreateProcessfromProcessTestBasehandles cleanup registration automatically). The skip conditions are preserved for Nano Server and Server Core.Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.
Original prompt
This section details on the original issue you should resolve
<issue_title>[8.0] Test failure in System.Diagnostics.Tests.ProcessTests.MainWindowHandle_GetWithGui_ShouldRefresh_Windows </issue_title>
<issue_description>## Build Information
Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=659152
Build error leg or test failing: System.Diagnostics.Tests.ProcessTests.MainWindowTitle_GetWithGui_ShouldRefresh_Windows
Pull request: #101098
Error Message
Fill the error message using step by step known issues guidance.
{ "ErrorMessage": "ProcessTests.cs(1782,0): at System.Diagnostics.Tests.ProcessTests.MainWindowHandle_GetWithGui_ShouldRefresh_Windows", "ErrorPattern": "", "BuildRetry": false, "ExcludeConsoleLog": false }Known issue validation
Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=659152
Error message validated:
[ProcessTests.cs(1782,0): at System.Diagnostics.Tests.ProcessTests.MainWindowHandle_GetWithGui_ShouldRefresh_Windows]Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 4/29/2024 10:22:00 PM UTC
Report
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.