Repository navigation
testing: Wait for a window to show on Linux before a step acts on it - #3110
Merged
Merged
Conversation
The app's `<Window>` opens hidden on Linux until the commit after the one that opened it is mounted, or `FIRST_FRAME` (150 ms) after it opened. Its views are not drawable until then, so `LinuxNative::bounds` has nothing to give and a step fails with "is not on screen (it has no native view)". The agent took the app as quiet after 100 ms without a batch, before that wait ran out: `Native::opening` kept its default on Linux. `LinuxNative::opening` now reads whether a window of the app's own is still waiting for its first frame, as macOS does since #2727.
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.
Description
The Linux workflow's step "Run the examples' tests in GTK windows" fails now and then on
main, always in a gallery test'sbeforeEach, on the first press afteropen():storage.test.tsx › clearing the storage asks first:`role:button[Storage]` is not on screen (it has no native view)form.test.tsx, two tests:`label:Input` is not on screen (it has no native view)In both, the screen texts listed after the error are the gallery's Home, so the row is in the app's tree; only its native view has no place on screen.
Root cause
Since window model v2, the gallery's first window is a window of the app's own (
mount(() => <Window id="main">…)). On Linux such a window opens hidden (window::open,pending: Some(false)) and shows with its first frame: on the commit after the one that opened it (batch_applied) orFIRST_FRAME(150 ms) after it opened. Until then its views are not drawable, andLinuxNative::boundsreturnsNonefor them (!view.is_drawable()), which is the step's "it has no native view".The test agent takes the app as quiet once no batch came for
QUIET(100 ms) and nothing the platform changes by itself is going on (Agent::changing:animating() || opening()). #2727 addedNative::openingfor exactly this, and implemented it on macOS only; its description notes that Linux (FIRST_FRAME) also keeps a new window hidden until its first frame. On Linuxopening()kept its defaultfalse, so when the app's first render is one commit,open()resolves about 100 ms after it, before the 150 ms wait runs out, and the first press finds the row with no drawable view. Whether a second commit comes in time decides the run, which is why it fails only sometimes, and more often on a busy runner, where the 150 ms timer fires late.Fix
LinuxNative::openingreadswindow::opening: whether a window of the app's own is still waiting for its first frame (AppWindow::pendingisSome). A step then waits for the window to show as it waits for an animation, as on macOS. The wait ends by itself: showing, hiding or theFIRST_FRAMEtimer clearspending, andSETTLE(2 s) still bounds every step. A window that is shown costs nothing.The developer guide and the testing guide (English and zh-CN) now say that Linux steps wait for an opening window too.
Public API
None.
Native::openingexists since #2727; this implements it for the Linux agent.How to Test
cargo test -p nsh-platform-linux --lib window::tests::a_new_window_is_opening_until_its_first_frame cargo clippy -p nsh-platform-linux -p nsh-linux-host -p nsh-linux-app --all-targets cargo clippy -p nsh-platform-linux --all-targets --features dev gh workflow run linux.yml --ref linux-gallery-nav-flakywindow::tests::a_new_window_is_opening_until_its_first_framechecks that a new window is opening until the commit after the one that opened it is mounted, and, without one, untilFIRST_FRAMEruns out.Verification
workflow_dispatchrun 45371761496:checkandgpui-gallerypass.window::tests::a_new_window_is_opening_until_its_first_framepasses in bothcargo test -p nsh-platform-linuxruns; clippy is clean; every example test file in GTK windows passes,form.test.tsx9/9 andstorage.test.tsx2/2 among them.mainafter the merge (b4c792510),workflow_dispatchrun 45374559502:checkandgpui-gallerypass, the new test included, and every example test file in GTK windows passes.