Skip to content

Fix flaky test_one_websocket_per_page after the offline test - #301

Merged
Archmonger merged 1 commit into
mainfrom
fix-flaky-one-websocket-per-page
Sep 22, 2026
Merged

Archmonger merged 1 commit into
mainfrom
fix-flaky-one-websocket-per-page

Conversation

@Archmonger

Copy link
Copy Markdown
Contributor

Description

The periodic (nightly) Test/python-source run #35684228566 failed with:

FAILED tests/test_app/tests/test_components.py::ComponentTests::test_one_websocket_per_page
    AssertionError: Expected 1 unique WebSocket URL, got 2:
    {'ws://localhost:33203/reactpy/?path=%2F&qs=',
     'ws://localhost:42647/reactpy/?path=%2Foffline%2F&qs='}
CLIENT ERROR: WebSocket connection to 'ws://localhost:42647/reactpy/?path=%2Foffline%2F&qs='
    failed: ... net::ERR_CONNECTION_REFUSED

Root cause. The tests share a single browser page across the whole ComponentTests class, and they run in alphabetical order — so test_offline_component runs immediately before test_one_websocket_per_page.

test_offline_component calls self._server_process_1.terminate() while the page is still sitting on the /offline/ page. Tearing down the server severs that page's WebSocket, but the page's client (createReconnectingWebSocket in src/js/src/websocket.ts) keeps retrying the now-dead port on a backoff timer for the rest of the session. Because the shared page is never navigated away, that zombie reconnect loop keeps firing new WebSocket() against the dead port during subsequent tests.

test_one_websocket_per_page attaches a "websocket" listener and navigates to /. Any zombie reconnect attempt from the dead /offline/ page that lands inside that navigation window is recorded, so the test sees two unique URLs (the home page and the leaked /offline/ one) and fails. This is inherently probabilistic, which is why the identical commit passed on the previous nightly runs and only failed this one — exactly the signature of a flaky CI test.

Fix. Navigate the shared page to about:blank at the end of test_offline_component. Leaving the document cancels its pending reconnect timers, so no zombie client is left to leak WebSocket connections into later tests. This is the same class of fix as the earlier timing-related flakiness addressed in #299 and keeps the fix entirely within the test harness (no product-code change).

A minimal A/B reproduction (kill the offline server, then mimic test_one_websocket_per_page) fails 8/8 without the about:blank navigation and passes 0/8 with it. The full ComponentTests class and the whole single_db suite pass locally after the change.

Checklist

  • Tests have been developed for bug fixes or new functionality. — No new assertion is needed; the existing test_one_websocket_per_page is the regression test, and it no longer flakes once the zombie reconnect is cleared.
  • The changelog has been updated, if necessary. — Not applicable: this is a test-only CI-robustness change with no user-facing or API impact (consistent with the test-only flakiness fix in Fix flaky CI tests #299).
  • Documentation has been updated, if necessary. — N/A.
  • GitHub Issues closed by this PR have been linked. — No issue exists for this specific flake; it was first observed via the periodic run above.

`test_offline_component` tears down the offline webserver while the shared
Playwright page is still on the /offline/ page. That page's client
(`createReconnectingWebSocket`) keeps retrying the now-dead port on a
backoff timer, so a reconnect attempt that lands inside the next test's
navigation window leaks a second WebSocket URL and flakes
`test_one_websocket_per_page` (observed intermittently on CI as
"Expected 1 unique WebSocket URL, got 2 ... /offline/").

Navigating to about:blank at the end of `test_offline_component` destroys
the document and cancels its pending reconnect timers, so later tests start
from a clean state.
@Archmonger
Archmonger marked this pull request as ready for review September 22, 2026 05:05
@Archmonger
Archmonger requested a review from a team as a code owner September 22, 2026 05:05
@Archmonger
Archmonger merged commit 4fd0434 into main Sep 22, 2026
23 checks passed
@Archmonger
Archmonger deleted the fix-flaky-one-websocket-per-page branch September 22, 2026 05:06
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