test(ws): reconnect-resubscribe + sporadic-channel live lane (Closes #169)#176
Merged
Merged
Conversation
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.
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.
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
Closes #169. Adds the two WS behaviors that weren't covered end-to-end.
tests/test_ws.py, keyless/offline): localwebsocketsserver drops the connection mid-stream; the test asserts the client reconnects, replayssorted(active)as a fresh SUBSCRIBE, and resumes streaming (distinguishable post-reconnect payload)._RECONNECT_BACKOFFmonkeypatched to 0.01 so it runs in <0.05s. NOT markedintegration— runs in the offline CI 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/listingis Pro+ tier. A non-Pro key is rejected at the handshake / closed with an auth code; the announcement test catcheswebsockets.exceptions.WebSocketExceptionandpytest.skips so a Basic key doesn't red the lane./liquidationstays 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 --checkandflake8clean on both files.