Skip to content

Commit cb4760d

Browse files
committed
Run transport security tests in process instead of over sockets
The SSE and StreamableHTTP security tests each spawned a uvicorn subprocess on a port picked by bind-then-close, then polled until the port accepted connections. Under pytest-xdist two workers can pick the same port in that window: the second server fails to bind, the readiness poll succeeds against the other worker's server, and the test asserts against a server configured with different security settings (e.g. 421 for a host the test explicitly allowed). Rewrite both files to drive the same Starlette apps in process through the interaction suite's StreamingASGITransport (re-exported from tests.interaction.transports as the sanctioned import point): no sockets, no subprocesses, no ports to race over. Assertions are unchanged. The new in-process GET test covers the validation-failure return in _handle_get_request; the pragma on that line was already stale (the success path has been driven in process by the interaction suite since it merged) and is removed. Also deflake test_idle_session_is_reaped, which slept 0.1s after a 0.05s idle timeout and failed on slow runners when the reaper had not fired yet. Re-requesting the session to poll for the 404 would push its idle deadline forward, so instead wait on the manager's "idle timeout" log record, which is emitted synchronously with the session being unregistered.
1 parent a938126 commit cb4760d

5 files changed

Lines changed: 212 additions & 454 deletions

File tree

src/mcp/server/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ async def _handle_get_request(self, request: Request, send: Send) -> None:
669669
await response(request.scope, request.receive, send)
670670
return
671671

672-
if not await self._validate_request_headers(request, send): # pragma: no cover
672+
if not await self._validate_request_headers(request, send):
673673
return
674674

675675
# Handle resumability: check for Last-Event-ID header
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Transport-specific interaction tests, and the in-process streaming bridge they are built on.
2+
3+
`StreamingASGITransport` is re-exported here as the sanctioned import point for test code
4+
outside this suite (the bridge module itself is suite-private).
5+
"""
6+
7+
from tests.interaction.transports._bridge import StreamingASGITransport
8+
9+
__all__ = ["StreamingASGITransport"]

0 commit comments

Comments
 (0)