Repository navigation
test(desktop): run what waits before the test loop draws again - #214
Merged
Merged
Conversation
TestSettingsChangeAPreferenceAndAVaultSetting timed out under the race detector on CI. The vault setting's round trip through notesd takes under a millisecond; the time went to frames. desktoptest.Loop.Until checked its condition, which draws a frame, after each posted function, and one setting change posts about 19 (the call's answer, vault.configured, the scan's events and the vault data each starts). Under the race detector a frame of the settings dialog costs about 200 ms here, so the wait grew to 4 s here and past the 10 s limit on a slower runner. Until now runs every function already waiting before it checks again, as the UI thread runs what was posted and then draws once. A function that posts itself again runs at the next check, so the deadline still holds. A vault setting also loaded the vault's data twice: once at the call's answer and once at vault.configured, which notesd sends after every change. The answer now loads it only when the change failed. Closes #203
Contributor
Author
|
Cross-review: Ready. Blocking: none. Findings: none.
|
The vault data's load asks sync.status, and a sync.changed event can come while it is asked: the two travel apart. The answer then replaced the event's newer status. After a join, the status bar could show syncing with no hub address until the loop changed state again. The window counts its vault's sync.changed events; a sync.status answer asked before one of them leaves the event's status in place. The test loop that runs what waits before it draws again found it: TestJoiningALoopbackHub timed out 6 times in 40 when the answer and the idle event ran in one batch.
A sync.changed that comes while sync.status is asked is not always newer than the answer: an event sent before a leave can come late, and keeping it would bring back the hub the vault left, with no event to follow. The event's status now stays only until a status asked after it comes: the window asks again, one ask at a time for each vault, until an answer comes with no event while it was asked.
An older ask's answer can come after a newer one: asked before a leave, it brought back the hub the vault left, and no event follows a leave. A vault switch and back let one through too, since the vault matched again. Each ask of sync.status now has a number; only the last ask's answer shows, and a sync.changed that came while it ran has it asked again.
Contributor
Author
|
Cross-review: Ready at The review took 1 pass and 3 re-reviews:
Revert tests: see the PR body. CI is green at |
bketelsen
approved these changes
Nov 12, 2026
5 tasks done
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.
Summary
TestSettingsChangeAPreferenceAndAVaultSettingtimed out now and then in the Race detector job (#203). The cause is the test loop, not notesd.What takes the time. Timed under
-raceon a desktop: the vault setting's round trip through notesd is under 1 ms. The 4 s went to 19 frames of about 200 ms each.desktoptest.Loop.Untilchecks its condition after every posted function, and the window tests' condition draws a frame. One setting change posts about 19 functions: the call's answer,vault.configured, the scan'svault.scanevents, and the catalog, panes and settings loads that they start. Some loads wait for an earlier answer, so they queue behind the frames. On a slower runner, with other race tests beside it, 19 frames go past the 10 s limit.The fix.
Loop.Untilnow runs every function that waits in the queue before it checks the condition again. This is what the UI thread does: it runs what was posted, then it draws once. When frames are slow, more work waits, and 1 frame covers it all. So the wait no longer grows with frame cost × answers. It runs only what waits at that moment: a function that posts itself again runs at the next check, so the deadline still holds.A vault setting loaded the vault's data twice: at the call's answer and at
vault.configured. notesd emits that event after every change it writes (internal/vault/configure.go). The answer now loads the data only when the change failed, so the rows show what holds. That removes a second catalog, panes and settings load for each change.A race this exposed. The first CI run of this branch failed
TestJoiningALoopbackHub: it failed 6 times in 40 here, against 0 in 40 on main. The vault data's load askssync.status. Async.changedevent can come while the call is in flight, because the two travel apart. The answer then replaced the event's newer status. The old loop checked between the two; the UI thread, like the new loop, runs both before it draws. After a join, the status bar could show "syncing" with no hub address until the loop changed state again. An event that crosses an answer can also be the older one: sent before a leave and delivered late, it would bring back the hub that the vault left, and no event follows a leave. An older ask's answer can also come after a newer one (asked before a leave, or before a switch to another vault and back). So each ask ofsync.statusnow has a number, and only the last ask's answer shows. If async.changedof the vault came while that ask ran, the event's status stays and the window asks again, until an answer comes with no event during its call.The 10 s limit is unchanged.
Closes #203.
Risk tier
Risk tier: 2 — test infrastructure, plus 2 behavior changes in the desktop app: the vault data load after a successful setting change now comes only from
vault.configured, and async.statusanswer that async.changedcrossed is asked again instead of shown. No path in.github/risk-paths.jsonmatches.Verification
make checkgreen (host).memory/corrections.jsonlfor the cross-review's blocking points on the sync statusgo test -race -count=50 -run '^TestSettingsChangeAPreferenceAndAVaultSetting$' -v ./internal/desktop/window/: 50 PASS, 0 FAIL; min 0.81 s, median 0.84 s, max 0.92 s. Before the fix, single runs took 4.8 to 7.6 s here.go test -count=60 -run '^TestJoiningALoopbackHub$' ./internal/desktop/window/: 60 PASS (6 of 40 failed before the sync fix)go test -count=1 ./internal/desktop/...3 times, andgo test -race -count=1 ./internal/desktop/..., greenTestUntilChecksOnceForWhatWaitsandTestUntilRunsOnlyWhatWaitsBeforeItChecks(internal/desktop/desktoptest/loop_test.go);TestAnEventWhileTheStatusIsAskedOutlivesTheAnswer,TestAnEventWhileTheStatusIsAskedIsSettledByAStatusAskedAfterIt,TestAnOlderSyncStatusAnswerDoesNotShowandTestASyncStatusAnswerFromBeforeAVaultSwitchDoesNotShow(internal/desktop/window/syncstatus_test.go)internal/desktop/desktoptest/desktoptest.goandinternal/desktop/window/settings.goto main. Keep the tests, then rungo test -count=1 -run TestUntil ./internal/desktop/desktoptest/.TestUntilChecksOnceForWhatWaitsfails:the condition ran 6 times for 1 batch, want 2. IntakeSyncStatus(internal/desktop/window/app.go), let the answer always replace the status, as main does. ThenTestAnEventWhileTheStatusIsAskedOutlivesTheAnswerfails:the answer replaced the event's status: <nil>. If the event is kept and no new ask is sent,TestAnEventWhileTheStatusIsAskedIsSettledByAStatusAskedAfterItfails:timed out waiting for the vault's status with no hub. If the ask's number is not checked,TestAnOlderSyncStatusAnswerDoesNotShowandTestASyncStatusAnswerFromBeforeAVaultSwitchDoesNotShowfail:an older answer showsandan answer from before the switch shows.