Repository navigation
refactor: let tests drive the hover delays with a clock of their own - #491
Conversation
WidgetPopup's hover delays waited on the real clock, so tests of them slept, or blocked the main actor to line up a race. WidgetPopup now takes a clock, the real one by default, and TestClock in the tests moves only when a test advances it. The two late-cancel tests use it instead of holding the main actor, and still fail without the cancellation checks from #483.
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
Before and after
50 unchanged screens
Visual review: 50 screens, none changed. |
|
🎉 This PR is included in version 0.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Problem
DECISIONS.md settles that code whose tests depend on time takes a clock, with the test clock in the repository.
WidgetPopup's hover delays slept on the real clock. So the tests that check them either slept for real or, in the two tests that reproduce #482's race, blocked the main actor withThread.sleepfor 250 ms. That adds the very main-actor contention that made tests flaky on CI.Changes
WidgetPopuptakes a clock (any Clock<Duration>,ContinuousClock()by default) for its three hover waits: the hover delay, the 200 ms steps of the path into a popup, and the close delay. The app behaves as before. Animation waits stay on the real clock.TestClock, in the tests:Four tests cover it.
aHoverCancelledAfterItsWaitRanOutDoesNotShowandaPopupEnteredAfterItsCloseDelayRanOutStaysOpenuse it instead ofholdMainActor, which is gone. They wait until the hover task is sleeping (and require it), advance the clock so the wait ends, then move into the popup before the main actor runs what's left. That's exactly A cancelled hover can still show a tooltip or close its popup when the Mac is busy #482's race, with nothing blocked.Not in this pull request:
hoveringPopupsWaitsAndKeepsBothTheWidgetAndPopupReachableand the hover triangle test still sleep for real. Moving them, then the expiry and failure-streak timers, comes next.Testing
TestClocktests and both converted tests pass.try Task.checkCancellation()lines from fix: keep a cancelled hover from showing a tooltip or closing its popup late #483 removed, both converted tests failed 3 of 3 runs. I put the lines back.pinnedPopupsStayOnScreenAndReturnUnderTheirWidgetand the two package review tests).Merging
One commit; any merge method works.
Claude Opus 5.5 via Claude Code