Commit de72011
committed
Run StreamableHTTP transport tests in process instead of over sockets
Final installment of the in-process test migration: this was the last
file spawning uvicorn subprocesses on bind-then-close ports with
readiness polling, which races under pytest-xdist when two workers pick
the same ephemeral port. Two tests in this file have flaked exactly
that way under parallel load.
All four subprocess servers (basic, JSON-response, event-store,
context-aware) become in-process apps served through the interaction
suite's StreamingASGITransport, held open by the session manager's
run() context. Raw `requests` calls become httpx calls against the
bridge client; the sync request-validation tests become anyio tests.
The second-GET-409 test now holds the first stream open by
construction, where the subprocess version noted it "might fail if the
first stream fully closed before this runs".
Assertions are unchanged, with documented exceptions now that the
server handlers run as traced in-process code:
- The long_running_with_checkpoints tool and the slow:// resource
branch had no callers and are removed, so the expected tools/list
count drops from 10 to 9 in five tests.
- Dead defensive arms become asserts (sampling non-text fallback,
close_sse_stream truthiness checks, the context server's unknown-tool
fallthrough and request checks), and the event store's
replay-from-unknown-event arm becomes a lookup that requires a stored
event, since unreachable branches now fail branch coverage instead of
hiding in an untraced subprocess.
- test_client_crash_handled no longer sleeps between crashing clients;
the bridge drains each client's teardown before the next connects.
Three pragmas in src/mcp/server/streamable_http.py covered only by the
formerly untraced subprocess (close_standalone_sse_stream, its session
message callback, and the JSON-mode Accept rejection) are now executed
by traced tests and removed.
With the last wait_for_server user migrated, the helper is deleted from
tests/test_helpers.py; run_uvicorn_in_thread stays for the websocket
smoke test.1 parent ed39e73 commit de72011
3 files changed
Lines changed: 937 additions & 1143 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
224 | | - | |
225 | | - | |
226 | 224 | | |
227 | 225 | | |
228 | 226 | | |
| |||
245 | 243 | | |
246 | 244 | | |
247 | 245 | | |
248 | | - | |
| 246 | + | |
249 | 247 | | |
250 | 248 | | |
251 | 249 | | |
| |||
421 | 419 | | |
422 | 420 | | |
423 | 421 | | |
424 | | - | |
| 422 | + | |
425 | 423 | | |
426 | 424 | | |
427 | 425 | | |
| |||
0 commit comments