Repository navigation
test: fix flaky tests - #10726
Merged
lizschwab merged 2 commits intoNov 30, 2026
Merged
test: fix flaky tests#10726lizschwab merged 2 commits into
lizschwab merged 2 commits into
Conversation
MutatorIcon and WarningIcon.setBubbleVisible wait for queued renders before opening or closing the bubble. Callers such as undoing a mutation change don't await it, so the block can be disposed in the meantime. The icon then built a bubble for the disposed block, or disposed the already-disposed mini workspace and fired a bubble_open event for it, which threw errors. Return after waiting if the block has been disposed; dispose() has already cleaned up the bubble. CommentIcon already does this via its rendered check. In the Node test run, the stray events were queued after teardown with their flush scheduled on a restored clock, so later procedure tests saw no events and failed intermittently. Part of RaspberryPiFoundation#10724
JSDom runs all of a window's animation frames from one setInterval, created with whatever setInterval is global at the time and reused until no frames are pending. Since jsdom 31, while any element has focus, attribute and style changes also start that interval, to check the element is still focusable (jsdom/jsdom#4434). focus_manager_test.js focused the body after sharedTestTeardown had restored the real timers, and nothing reset that, so every later test in the worker started the interval when its teardown changed the DOM after the restore. Later tests' frames then ran on a real interval their fake clock couldn't control. Blockly fires events after a frame, so those tests saw events late or not at all, depending on load and which files shared a worker. Clear focus in sharedTestTeardown while the fake clock is still installed, and drop the body focus from focus_manager_test.js's teardown, which the blur now covers. Part of RaspberryPiFoundation#10724
Collaborator
Author
|
I guess the best fix for the PR title lint is probably to split this, but another green run with both together would be good to see first. |
Contributor
|
Thanks @microbit-matt-hillsdon ! I was also poking at this last week, but I like this approach better. I think this should be good to merge if you want to un-draft it. |
lizschwab
approved these changes
Nov 30, 2026
lizschwab
left a comment
Contributor
There was a problem hiding this comment.
Looks good. I pulled down the changes and tested them locally and everything looks good. Thanks for taking this on!
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.
The basics
The details
Resolves
Fixes #10724 (hopefully, draft pending CI pass, if it passes then a re-run would be nice to confirm)
Analysis
After hitting the flakes in the PR tests for #10723 I had an LLM review recent CI failures and hammer the tests under load. The investigation was LLM supported and the fixes were LLM generated. I've reviewed the logic of the failure modes and the fixes.
Recent failures in CI (LLM-generated table from GitHub data):
All of these runs came after #10712 (jsdom 30.1.3 to 31.0.1) merged on 23 November, which relates to one of the fixes.
I can reproduce the flakes locally on main: they failed in 6 of 12 full runs with 3 workers and the CPU loaded.
Further investigation found the workspace comment tests failed every time when
focus_manager_test.js, or any test that focuses the body, ran first in the same process (build first). This one's easy to repro:The procedures tests for parameter rename/delete/reorder also failed on their own about a quarter of the time. I didn't see this in CI.
Proposed Changes
There are two separate issues contributing to the flakes I see. I've done one PR with two commits to see clean builds in CI but happy to split this for merge if desired.
The procedures test flakes I saw locally show up a minor async bug which I've fixed in c117135. Although a real bug, I expect in practice it only shows up in the tests as it's very timing dependent.
The other issue relates to how jsdom schedules animation frames. It uses setInterval, which
sharedTestSetup/sinon swaps out for fakes. The realsetIntervalis later restored insharedTestTeardown. jsdom's rendering interval uses whatever setInterval is current when it starts and sticks with it until idle.The teardown in
focus_manager_test.jsfocuses the body; this carries through into subsequent tests. Since jsdom 31 (jsdom/jsdom#4434), any attribute or style change while an element has focus starts the rendering interval to do focus fixup (checking the current element is still focusable). Some of these changes happen after the real timers have been restored (e.g. teardown removing the widget div).Blockly fires events after an animation frame and leans on
clock.runAll()to make sure they're seen by tests. But if the frame runs on the real interval thenrunAllwon't run them, so tests miss events non-deterministically.The smallest fix is to reset focus systematically, before restoring timers. I've taken that approach in 8e80821.
An alternative, that might be more robust to badly behaved tests, is to replace jsdom's RAF implementation in node-setup.mjs, e.g.
As this always delegates to
setTimeoutit can be replaced as needed by the tests. But this is a more invasive change.