Skip to content

test: deflake the background socket test - #57

Merged
boehlerlukas merged 1 commit into
mainfrom
test/deflake-background-socket
Oct 11, 2026
Merged

boehlerlukas merged 1 commit into
mainfrom
test/deflake-background-socket

Conversation

@boehlerlukas

Copy link
Copy Markdown
Contributor

GleapWebSocketTests.testNoSocketOpensInTheBackgroundUntilTheAppReturns failed on main after the 19.2.3 and 19.2.4 merges.

Cause. The test hostname ws.gleap.test does not resolve. After the first lookup the failure is cached, so a socket fails about 2–3 ms after it opens. The helper then clears webSocketTask in reconnectAfterFailure. The test checked webSocketTask every 20 ms (one waitUntil run-loop slice), so it only passed when a check happened to land inside that window. It had two chances in 5 s: the connect 1.5 s after the foreground notification, and the first retry 1.6–2.4 s later. Reproduced locally: 1 of 8 repetitions failed with "did not connect after returning to the foreground".

Fix (test only). The test now records every socket the helper opens by observing webSocketTask with KVO, so a short-lived socket still counts. It also pins the internal online flag to true (via KVC) so the path monitor's state can't affect the test, and it waits up to 10 s. The background assertion is also stricter now: no socket for the channel may open at all in the background, not just be open at the moment of the check.

There is no production change: the helper connects 1.5 s after returning to the foreground, as designed.

Verification. GleapWebSocketTests passed 20/20 with -test-iterations 20 (it had failed 1/8 before the fix), and .github/scripts/test.sh was run 5× on the full suite.

🤖 Generated with Claude Code

ws.gleap.test does not resolve, so the socket the helper opens on returning to the
foreground fails a few milliseconds later (the lookup is cached after the first one)
and is cleared right away. The test polled webSocketTask every 20 ms and missed that
window now and then. It now records every socket the helper opens (KVO on
webSocketTask), pins the online flag and waits up to 10 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boehlerlukas
boehlerlukas merged commit 42a0df7 into main Oct 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant