Skip to content

Commit 03fdaed

Browse files
committed
tests: expect SSE session-entry cleanup on disconnect
connect_sse now removes _read_stream_writers[session_id] in a finally once the GET request unwinds (#2719), so the endpoint-event test waits for that cleanup after the client disconnects instead of pinning the old retention behaviour.
1 parent 2ca7f4c commit 03fdaed

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tests/interaction/transports/test_sse.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
@requirement("transport:sse:endpoint-event")
3030
async def test_endpoint_event_names_the_message_endpoint_with_a_fresh_session_id() -> None:
3131
"""Connecting opens a GET stream whose first event names the POST endpoint and a fresh
32-
session id; messages POSTed there are answered on that stream.
33-
34-
On v1 the server's session entry is not removed on disconnect (`SseServerTransport` never
35-
pops `_read_stream_writers[session_id]`); the final assertion pins that behaviour.
36-
"""
32+
session id; messages POSTed there are answered on that stream, and disconnecting releases the
33+
server's session entry."""
3734
app, sse = build_sse_app(Server("legacy"))
3835
captured_session_id: list[str] = []
3936

@@ -60,7 +57,13 @@ def httpx_client_factory(
6057
assert UUID(hex=captured_session_id[0]) in sse._read_stream_writers
6158
assert await client.send_ping() == snapshot(EmptyResult())
6259

63-
assert UUID(hex=captured_session_id[0]) in sse._read_stream_writers # pragma: lax no cover
60+
# `connect_sse` drops the session entry in a `finally` once the GET request has unwound; the
61+
# bridge lets that unwinding finish after the client has gone, so wait for the cleanup instead
62+
# of racing it. How many iterations that takes is a scheduling accident (usually zero), and on
63+
# 3.11 these post-unwind lines are invisible to the line tracer, hence the coverage exclusion.
64+
with anyio.fail_after(5): # pragma: lax no cover
65+
while sse._read_stream_writers:
66+
await anyio.sleep(0.01)
6467

6568

6669
@requirement("transport:sse:post:session-routing")

0 commit comments

Comments
 (0)