Repository navigation
[bot] Fix flaky coverage of the closed check in the client WebSocket heartbeat - #14433
Dreamsorcerer wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #14433 +/- ##
=======================================
Coverage 99.12% 99.12%
=======================================
Files 135 135
Lines 53661 53678 +17
Branches 2737 2737
=======================================
+ Hits 53191 53210 +19
+ Misses 356 355 -1
+ Partials 114 113 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
This is from an agent via my MCP server, a human will verify it soon.
What do these changes do?
if self._closed: returninClientWebSocketResponse._handle_ping_pong_exception(aiohttp/client_ws.py:217-218) is only covered on some nightly runs, so Codecov flips by 2 lines on commits that can't change coverage (e.g. 2091405, 0ae5b96, b2350c3, b60c612). Per-flag data shows only thePy-pypy-3.12job ever hits it.After a clean
close(), the server's CLOSE frame, like any received data, re-arms the heartbeat (_on_data_received→_reset_heartbeatdoesn't check_closed).test_close_websocket_while_ping_inflightandtest_heartbeat_does_not_timeout_while_receiving_large_frameend straight after such a close withheartbeat=0.1, so the stale heartbeat only fires, and its failed PING reaches the guard, if fixture teardown takes over 100 ms. On PyPy the pure-Python coverage tracer makes pytest-cov's per-test context switch slow enough for that on some runs; on CPython it never happens.This adds
test_heartbeat_after_close, which waits for that heartbeat (and its PONG timeout) after a close and checks the close code and exception are left alone, so the guard is covered on every run.The
send_frameassertion relies on the re-arm, which is the client-side counterpart of #14125. If that is fixed for the client too, this test should be revisited with it.Are there changes in behavior for the user?
No, test-only.
Is it a substantial burden for the maintainers to support this?
No.
Related issue number
N/A (related: #14125)
Checklist
CONTRIBUTORS.txt(N/A)CHANGES/folderLocal verification
test_close_websocket_while_ping_inflight|teardown. On CPython 3.11/3.13 it was missed in every run.tests/test_client_ws.py tests/test_client_ws_functional.py: 105 passed on CPython 3.11–3.13; 103 passed, 2 skipped (isal) on 3.14, 3.15, 3.15t and PyPy.assert 1006 == 1000).