Skip to content

test: keep timing tests reliable while other tests hold the main actor - #109

Merged
M4n0x merged 1 commit into
mainfrom
test/flaky-timing-tests
Oct 19, 2026
Merged

M4n0x merged 1 commit into
mainfrom
test/flaky-timing-tests

Conversation

@M4n0x

@M4n0x M4n0x commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

Since 2026-10-17, CI has failed on main after merging #66, #98, #102 and #108, and in pull requests, with no real regression (the run for #108, for example). Three tests flake:

Test Failed runs Failure
aContinuousRunThatStayedOpenStartsANewFailureStreakWhenItFails 8 nextDelay is 1.0 instead of 2.0
temporaryOutputShowsItsFieldsForItsDurationThenExpires 4 a 1-second temporary output still shows after 10 seconds
widgetActionsRunInOrderAndStoppingCancelsQueuedWork 2 the action log is out of order

Swift Testing runs the tests in parallel, and almost all of them are @MainActor, so they take turns on one thread. On the CI runner the native rendering tests hold it so long that tests which never wait report 2 to 14 seconds spent waiting for their turn. This part of the run grew from 8 seconds on 10-17 to 24–36 seconds. Each of these tests bounded that wait with the clock: 300 ms before a run counts as steady, a 10-second deadline for a 1-second expiry, and a 4-second timeout on an action the test releases.

Changes

Tests only. Each test still checks the same behavior, without timing the main actor:

  • Failure streak (DataSourceTests): the two runs that fail at once get 60 seconds before they count as steady, so waiting for the main actor can't make them steady. Only the run that has to stay open gets 300 ms. Its 400 ms sleep is a minimum, which delays only lengthen.
  • Temporary output (PresentationTests): expiry(of:) counts polls instead of watching a deadline. When the main actor stalls, the expiry runs before the next poll, while a deadline could pass first. The test uses this helper instead of its own 10-second loop, and the helper's other caller, theSameTemporaryOutputShowsAgainAfterItExpires, gets the same fix.
  • Widget actions (ScriptEventTests): the action the test releases now times out after 60 seconds instead of 4. store.stop() still ends it if the test fails early.

Testing

  • Reproduced each failure locally by running the flaky test next to a scratch test that blocks the main actor (400 ms bursts, one 11-second stall, or 4.5-second bursts) with swift test --filter. All three failed with the same messages and lines as on CI. With this change, the same pairs pass in three rounds each. The scratch test isn't committed.
  • swift test --filter on the four tests this changes passes, as fast as before (0.1–1.4 seconds each).
  • Mutated ScriptWidget so that a failure never starts a new streak, then so that every continuous failure does. The failure streak test still fails for both.
  • I didn't run the whole suite locally; CI runs it on this pull request.

Merging

Any method works: it's one test: commit whose message matches the title, and it makes no release.

Claude Opus 5.5 via Claude Code

Swift Testing runs the tests in parallel, and almost all of them share the main actor. On CI the
native rendering tests hold it so long that a test can wait seconds for its next turn, so three
tests that bounded that wait with the clock failed on main and in pull requests.

- The failure streak test gave runs that fail at once 300 ms before they counted as steady. They
  now get 60 seconds; only the run that has to stay open gets 300 ms.
- The temporary output test let a 10-second deadline pass while the expiry waited behind its poll.
  expiry(of:) now counts polls instead, and the test uses it.
- The widget actions test timed out its first action after 4 seconds, before the test released it.
  The timeout is now 60 seconds, and stopping the store still ends the action.
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner October 19, 2026 17:35
@M4n0x
M4n0x merged commit 17feb6e into main Oct 19, 2026
4 checks passed
@M4n0x
M4n0x deleted the test/flaky-timing-tests branch October 19, 2026 17:40
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant