fix: add HTTP readiness check to wait_for_server and remove dead code in SSE tests#2073
Merged
Kludex merged 2 commits intomodelcontextprotocol:mainfrom Feb 17, 2026
Merged
Conversation
…modelcontextprotocol#1777) The flaky SSE tests (test_sse_client_basic_connection_mounted_app, test_request_context_isolation) fail intermittently because wait_for_server() only checks TCP port connectivity. On slow CI machines, the port may accept connections before the ASGI app is fully initialized, causing SSE requests to fail. - Add a two-stage readiness check to wait_for_server(): first TCP connect, then an actual HTTP request to verify the app is handling requests (any HTTP response, even 404, confirms readiness) - Remove unreachable dead code after blocking server.run() calls in run_server() and run_mounted_server() - Remove unused `time` import from test_sse.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
The HTTP health check in wait_for_server() caused false-positive readiness signals for mounted Starlette apps (404 from root vs 404 from uninitialized routes are indistinguishable). Revert to TCP-only polling which matches the original behavior. Also remove the same dead-code pattern from test_ws.py (unreachable loop after blocking server.run()). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Kludex
approved these changes
Feb 17, 2026
Member
|
Thanks! |
Contributor
Author
|
Thanks for the quick review, @Kludex! Happy to contribute 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1777 — removes dead code that could never execute in the SSE and WebSocket test server setup functions.
Root cause
In
run_server(),run_mounted_server()(test_sse.py) andrun_server()(test_ws.py), there is awhile not server.startedpolling loop placed afteruvicorn.Server.run(). Sincerun()blocks until the server shuts down, the polling loop is unreachable dead code. Server readiness is already handled by thewait_for_server()helper in the test fixtures.Changes
tests/shared/test_sse.py: Remove unreachablewhile not server.startedloops fromrun_server()andrun_mounted_server(), and the now-unusedimport timetests/shared/test_ws.py: Remove the same dead code pattern fromrun_server(), and the now-unusedimport timeTest plan
ruff checkpasses🤖 Generated with Claude Code