From 0d66c016ff5db313c7f06bd8bd9869b422aed190 Mon Sep 17 00:00:00 2001 From: byrongamatos Date: Fri, 10 Jul 2026 21:26:16 +0200 Subject: [PATCH] =?UTF-8?q?test(ws=5Fhighway):=20assert=20streaming=20stop?= =?UTF-8?q?s=20after=20disconnect=20(exactly=20one=20send)=20=E2=80=94=20C?= =?UTF-8?q?odeRabbit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The stub now raises only on the first send and the test asserts ws.sends == 1, so a handler that caught the disconnect and kept streaming would fail. Still negative-checked: removing the guard fails the test. --- tests/test_ws_highway_disconnect.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_ws_highway_disconnect.py b/tests/test_ws_highway_disconnect.py index 30ad39f..3e97df0 100644 --- a/tests/test_ws_highway_disconnect.py +++ b/tests/test_ws_highway_disconnect.py @@ -45,7 +45,11 @@ class _DisconnectingWS: async def send_json(self, data): self.sends += 1 - raise WebSocketDisconnect(code=1001) + # Raise only on the FIRST send. If the handler wrongly kept streaming + # after catching the disconnect, later sends would succeed and `sends` + # would climb past 1 — the exactly-one assertion catches that. + if self.sends == 1: + raise WebSocketDisconnect(code=1001) async def receive_text(self): raise WebSocketDisconnect(code=1001) @@ -101,6 +105,6 @@ def test_midstream_disconnect_is_not_logged_as_error(server): finally: lg.removeHandler(cap) - assert ws.sends >= 1, "handler never reached a streamed send" + assert ws.sends == 1, f"handler kept streaming after the disconnect ({ws.sends} sends)" unhandled = [m for m in cap.messages if "highway_ws unhandled error" in m] assert not unhandled, f"disconnect logged as unhandled error: {unhandled}"