Repository navigation
Fix the menu bar recovery test flakes - #49
Merged
Merged
Conversation
testRevokeAllTurnsTheRelayOffAndAKeyScopedRevokeLeavesItOn and testTurningTheRelayOnRefusesWhatItCanBeforeTouchID turned the relay off right after setRelay(enabled: true) and then asserted the fake socket was closed. The relay loop dials on a detached task, so on a slow runner (ThreadSanitizer on CI) the cancel can land before the dial: the loop sees the cancellation, ends without ever opening the socket, and there is nothing to close. Under TSan with eight busy CPU hogs locally this failed 11 of 30 and 1 of 30 runs. Both tests now wait for the connected state first, as the other host tests in the class already do. The product behaviour is right as it is: a relay turned off before it dials never dials.
testRecoveryWaitsForMenuToClose and its neighbours slept 150 ms after a 20 ms recovery delay and then asserted the status item had been replaced. Recovery runs on the main actor, and on a slow CI runner it ran later than that: run 42090154795 logged "menubar item recovered" after the failed asserts, in a test that took 0.89 s. Locally, the old file failed 17 of 30 runs at background QoS with eight CPU hogs (wake and hidden-item tests). The positive checks now poll until the item is replaced (30 s ceiling; a throttled local run stalled the main thread past 5 s). Checks that nothing was replaced keep a short fixed wait, since a late recovery can only make those pass. The burst test only asserts "not yet replaced" for steps where no gap between requests reached the delay, the one case in which recovery may legitimately fire. MenubarItemController is unchanged.
testSocketDropCancelsOpenRequestsAndReconnects failed once on a9f9132 with the backoff list read as [] although the second socket had been dialed. The cause was a test-side data race: the pinger appended a 3600 s keepalive sleep to RecordingSleeper every millisecond while the test read the array without the lock. ThreadSanitizer reports exactly that race when the a9f9132 helper is put back, and f0598da already fixed it by reading under the lock; the test has not failed on CI since. What was left is the busy keepalive itself: thousands of recorded entries and lock round-trips per run, filtered out at the end. RecordingSleeper can now park one sleep length until cancelled, so the keepalive never ticks and the test asserts the exact backoff list, [1].
This reverts commit e4197fa.
…tests" This reverts commit 262bbc6.
When a slow runner lets a gap in the burst reach the recovery delay, a recovery fires mid-burst and the remaining requests correctly schedule one more. The test took the first replacement as final and then failed its coalescing check when the second one swapped the item. It now waits for the item to hold still for longer than the delay in that case only; a burst with no long gap keeps the strict check. The test also stops its controller on any early exit, like its neighbours.
Merged
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.
What and why
MenubarRecoveryTests.testRecoveryWaitsForMenuToCloseand its neighbours failed on CI from timing alone. They gave a 20 ms recovery a fixed 150 ms window, and on a slow runner recovery ran later: in run 42090154795 the "recovered" log line came after the failed asserts.MenubarItemController.swiftis untouched, so the product is unchanged.replaced(_:from:within:), up to 30 s). A passing run returns as soon as it happens. The 30 s ceiling is there because a throttled local run stalled the main thread for over 5 s.Dropped from this branch (reverted in the history; net diff is one file):
feat/relay-doorbell, 33596aa) fixes the same two races with its ownwaitConnected, and the two branches conflicted.RecordingSleeper.delays) was already fixed on main by f0598da, and parking the keepalive would have removed pinger-versus-drop coverage from that test.How tested
swift test --filter MenubarRecoveryTests5× gaveExecuted 4 tests, with 0 failureseach time, and 15× at background priority (taskpolicy -b) passed 15/15.defer.Risks
Test-only. On a broken build a "was replaced" check now takes up to 30 s to fail instead of 150 ms.
What's left
RelayTests.testFailedKeepalivePingClosesTheSocketAndReconnects, under TSan in run 42101992705: a second ping fits in before the receive loop cancels the keepalive. Production impact is a duplicate log line, and the fix would touchRelay.swift.AppUpdaterTests.testABackgroundRestartThatKeepsFailingIsLeftForTheNextCheck, in run 41973500586: 2 against 3.