Skip to content

fix: add HTTP readiness check to wait_for_server and remove dead code in SSE tests#2073

Merged
Kludex merged 2 commits intomodelcontextprotocol:mainfrom
BabyChrist666:fix/flaky-sse-tests-1777
Feb 17, 2026
Merged

fix: add HTTP readiness check to wait_for_server and remove dead code in SSE tests#2073
Kludex merged 2 commits intomodelcontextprotocol:mainfrom
BabyChrist666:fix/flaky-sse-tests-1777

Conversation

@BabyChrist666
Copy link
Contributor

@BabyChrist666 BabyChrist666 commented Feb 17, 2026

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) and run_server() (test_ws.py), there is a while not server.started polling loop placed after uvicorn.Server.run(). Since run() blocks until the server shuts down, the polling loop is unreachable dead code. Server readiness is already handled by the wait_for_server() helper in the test fixtures.

Changes

  • tests/shared/test_sse.py: Remove unreachable while not server.started loops from run_server() and run_mounted_server(), and the now-unused import time
  • tests/shared/test_ws.py: Remove the same dead code pattern from run_server(), and the now-unused import time

Test plan

  • All existing SSE and WebSocket tests continue to pass
  • No functional behavior changes — only dead code removal
  • ruff check passes

🤖 Generated with Claude Code

…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>
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 Kludex merged commit 3b53fb9 into modelcontextprotocol:main Feb 17, 2026
27 checks passed
@Kludex
Copy link
Member

Kludex commented Feb 17, 2026

Thanks!

@BabyChrist666
Copy link
Contributor Author

Thanks for the quick review, @Kludex! Happy to contribute 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix flaky SSE tests: test_sse_client_basic_connection_mounted_app and test_request_context_isolation

2 participants