Skip to content

test(ws): reconnect-resubscribe + sporadic-channel live lane (Closes #169)#176

Merged
martinkersner merged 4 commits into
mainfrom
issue-169-ws-integration-tests-reconnect
Jul 5, 2026
Merged

test(ws): reconnect-resubscribe + sporadic-channel live lane (Closes #169)#176
martinkersner merged 4 commits into
mainfrom
issue-169-ws-integration-tests-reconnect

Conversation

@martinkersner

Copy link
Copy Markdown
Member

Summary

Closes #169. Adds the two WS behaviors that weren't covered end-to-end.

  • Reconnect-with-resubscribe (tests/test_ws.py, keyless/offline): local websockets server drops the connection mid-stream; the test asserts the client reconnects, replays sorted(active) as a fresh SUBSCRIBE, and resumes streaming (distinguishable post-reconnect payload). _RECONNECT_BACKOFF monkeypatched to 0.01 so it runs in <0.05s. NOT marked integration — runs in the offline CI lane.
  • Sporadic-channels live lane (tests/test_ws_live.py, keyed/opt-in): integration-marked, importorskip-guarded, skips without a key. Exercises /liquidation (BTC-USDT@binance) and /announcement/listing (no param). Sporadic, so a quiet window (asyncio.TimeoutError) is a PASS — the value is that connect + auth + SUBSCRIBE succeed without raising.

Known limitations

  • /announcement/listing is Pro+ tier. A non-Pro key is rejected at the handshake / closed with an auth code; the announcement test catches websockets.exceptions.WebSocketException and pytest.skips so a Basic key doesn't red the lane. /liquidation stays strict.

Test plan

  • python -m pytest tests/ -m "not integration" -q → 212 passed, 11 skipped, 109 deselected. New reconnect test runs and passes (0.04s).
  • python -m pytest tests/test_ws_live.py -q → 2 skipped cleanly (no key); the lane is deselected from the offline run.
  • black --check and flake8 clean on both files.

Local websockets-server test: drop the conn mid-stream, assert the
client reconnects and replays sorted(active) SUBSCRIBE, then resumes.
Backoff monkeypatched tiny for speed. Keyless, offline lane.
Opt-in integration lane for /liquidation and /announcement/listing.
Tolerates quiet windows (TimeoutError = pass). Announcement is Pro+;
skip on handshake/auth rejection so a Basic key doesn't red the lane.
@martinkersner martinkersner self-assigned this Jul 5, 2026
Default reconnect=True swallows a post-connect auth close in the reader
loop, so the skip-on-rejection path never fired (test just timed out
and passed). Disable reconnect so the close propagates to the skip.
With reconnect=False a post-connect auth close ends the stream, so
__anext__ raises StopAsyncIteration (not a WebSocketException) — the
prior catch missed it and the test would error. Catch both so both
rejection modes skip; a quiet Pro conn still times out and passes.
@martinkersner martinkersner merged commit 252a59c into main Jul 5, 2026
5 checks passed
@martinkersner martinkersner deleted the issue-169-ws-integration-tests-reconnect branch July 5, 2026 10:27
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.

WS: integration tests for reconnect + sporadic channels (/liquidation, announcement)

1 participant