Repository navigation
fix(winforms): isolate WinForms test message loops and initialize the toolkit once - #3
Merged
Conversation
…once Windows managed tests failed in the v0.3.0 Release build with PdVm.Tests.PdVmTypedDotNetInteropTests.WinFormsButtonClickInvokesRssCallbackOnTheOwningStaThread asserting "updated" but getting null: the click callback never ran and the form never closed. The WinForms test classes ran concurrently and shared process-global Windows Forms state: * every test called Application.EnableVisualStyles/SetHighDpiMode, but those only take effect before the first window handle exists, so a later test saw InitializeWindowsFormsApplication() return false or raced the first form; * the 3s watchdog called Application.Exit(), which tears down every message loop in the process, so one test's timeout killed the other tests' loops - the click test then lost Shown/Click dispatch and reported no signal; * first-use toolkit initialization (assembly load, GDI+/fonts/themes, first Application.Run) took ~2-3.5s on the runner and landed inside that 3s deadline, so the watchdog fired before the callback chain completed. Put the WinForms tests in one non-parallel collection, initialize Windows Forms once per process (with a throwaway message loop outside any test deadline), and give the session a CloseMainForm() that closes only its own form instead of exiting every loop in the process. Test semantics are unchanged: the button click must invoke the RSS callback, update the label to "updated" and close the form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Releaserun 43890270237 (Package win-x64→Test managed projects, HEAD85b4e16) failed with 83/84 passing:threadErrorwasnulland the signal file was never written: the click callback never ran and the form was never closed, yet nothing reported an error. The same test passed in theIronRust CIwindows job on the same commit (taking ~2 s instead of ~80 ms), so the failure is ordering/timing dependent.Root cause
The three Windows Forms test classes (
PdVmTypedDotNetInteropTests,PdVmDotNetHostTests,PdVmMinesweeperTests) ran in parallel while sharing process-global Windows Forms state:Application.Exit()was used as the per-test watchdog.Exittears down every message loop in the process, not just the caller's. A watchdog firing in one test therefore terminated another test'sApplication.Run– the click test then lost itsShown/Clickdispatch, its own watchdog fired 3 s later, and the callback never posted. Reproduced directly: with two message loops live in one process, a 3 sExitin test A ended test B's loop at 3567 ms with itsShownsignal still missing, and also failedPdVmDotNetHostTests.ConstructsWindowsFormOnStaThreadWithoutCompileTimeWindowsDependency(8 ms).Application.SetHighDpiMode/EnableVisualStyles, which only take effect before the first window handle exists. Once any test had created a form,PdVmDotNetHost.InitializeWindowsFormsApplication()returnedfalse(or ran concurrently with the first form), even though the toolkit was fine.windows-latest: firstApplication.Runin the process took ~2–3.5 s (assembly load, GDI+/fonts/themes, first window) versus 18–31 ms for later iterations. That cost was inside the test's 3 s watchdog, so the watchdog could fire before the interaction even started.Fix
WinFormsCollection(DisableParallelization = true) and put every form-creating test class in it, so Windows Forms tests never run concurrently.WinFormsTestSupport: initializes Windows Forms once per process (thread-safe) and pumps a throwaway message loop so one-time toolkit startup happens outside any test's deadline. All tests now assert against that single initialization result.PdVmWinFormsApplicationSession.CloseMainForm(): closes the session's own main form on its UI thread (through the same path asEventLoop::Close, so a boundFormClosingcannot veto it) instead ofApplication.Exit(). The two message-loop tests use it for their watchdog, so a timeout terminates only the loop under test.ExitWindowsFormsApplicationhelper.Test semantics are unchanged: the click must invoke the RSS callback, the label must read
updated, and the form must close. No assertion was relaxed, removed, or skipped, and no timeout was raised.Verification
IronRust CI43923832143 – windows-latest: 84/84 passed, 0 warnings;WinFormsButtonClickInvokesRssCallbackOnTheOwningStaThreadnow 82 ms (was 2–3 s).Release43925319854 (workflow_dispatch on this branch, the exact job that failed):Package win-x64→Test managed projects84/84 passed, package step succeeded.dotnet test PdVm.Tests -c Release→ 84/84 passed; the WinForms tests return early on non-Windows, so real UI coverage is the Windows jobs above.cargo test --locked(native compiler): 8 + 9 tests passed.Files
PdVm.Runtime/PdVmWinFormsApplication.cs–CloseMainForm(), volatile main-form publication.PdVm.Tests/WinFormsTestSupport.cs(new) – non-parallel collection, one-time initialization and warm-up.PdVm.Tests/PdVmTypedDotNetInteropTests.cs,PdVm.Tests/PdVmDotNetHostTests.cs,PdVm.Tests/PdVmMinesweeperTests.cs– collection membership, shared initialization, loop-local watchdog.Based on
master@85b4e16(the HEAD of the failing run).