Skip to content

Commit b732867

Browse files
committed
Verify SSE request-context isolation inside each connection block
Statements after the connection loop sit in the Python 3.11 trace-loss shadow (python/cpython#106749) and were reported uncovered on 3.11 matrix cells; verifying inside the traced region removes the gap without a coverage exclusion.
1 parent 39938a2 commit b732867

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

tests/shared/test_sse.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,11 @@ async def test_request_context_propagation() -> None:
371371
async def test_request_context_isolation() -> None:
372372
"""Each SSE connection's handlers see only that connection's request headers."""
373373
factory = in_process_client_factory(make_context_server_app())
374-
contexts: list[dict[str, Any]] = []
375374

376-
# Connect three clients in turn, each with its own headers.
375+
# Connect three clients in turn, each with its own headers. Each connection is
376+
# verified inside its own block: on Python 3.11 the line tracer is lost once an
377+
# async-with teardown throws (python/cpython#106749), so statements placed after
378+
# this loop would be reported uncovered on some matrix cells.
377379
for i in range(3):
378380
headers = {"X-Request-Id": f"request-{i}", "X-Custom-Value": f"value-{i}"}
379381

@@ -386,13 +388,10 @@ async def test_request_context_isolation() -> None:
386388
assert len(tool_result.content) == 1
387389
content = tool_result.content[0]
388390
assert isinstance(content, TextContent)
389-
contexts.append(json.loads(content.text))
390-
391-
assert len(contexts) == 3
392-
for i, ctx in enumerate(contexts):
393-
assert ctx["request_id"] == f"request-{i}"
394-
assert ctx["headers"].get("x-request-id") == f"request-{i}"
395-
assert ctx["headers"].get("x-custom-value") == f"value-{i}"
391+
ctx = json.loads(content.text)
392+
assert ctx["request_id"] == f"request-{i}"
393+
assert ctx["headers"].get("x-request-id") == f"request-{i}"
394+
assert ctx["headers"].get("x-custom-value") == f"value-{i}"
396395

397396

398397
def test_sse_message_id_coercion() -> None:

0 commit comments

Comments
 (0)