Test lifespan fires once per process over HTTP - #4480
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 991336be6f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def ping() -> str: | ||
| return "pong" | ||
|
|
||
| async with run_server_async(server, transport="http") as mcp_url: |
There was a problem hiding this comment.
Exercise the session manager without pre-entering lifespan
This test is meant to catch _lifespan_proxy / StreamableHTTPSessionManager reverting to per-session lifespan behavior, but run_server_async goes through server.run_http_async(), which already wraps uvicorn in async with self._lifespan_manager() (fastmcp_slim/fastmcp/server/mixins/transport.py:322-324). Since _lifespan_proxy is ref-counted and explicitly reuses an existing outer lifespan, a regression where the HTTP session manager enters the proxy once per client session would still keep enter_count == 1 and exit_count == 0 here, so the new regression test can pass while the behavior it claims to guard is broken; serving server.http_app() without the outer manager would exercise the intended path.
Useful? React with 👍 / 👎.
| # The session manager entered the lifespan exactly once across every | ||
| # session, and the user lifespan was entered once and exited once at | ||
| # process shutdown. | ||
| assert proxy_enter_count == 1 |
#4446 drove the FastMCP lifespan through the SDK session manager, making the user lifespan fire once per process instead of once per session — but the only test asserting once-per-process semantics ran over the in-memory transport, not the HTTP path where the SDK manager is actually in the loop. This adds a regression test that runs a real HTTP server and asserts, with an enter/exit counter, that the user lifespan enters exactly once and stays open across three sequential and two overlapping client sessions, exiting once at shutdown. If anyone ever reworks the
_lifespan_proxy/session-manager wiring, this is the test that catches a silent regression to per-session semantics.Label: chores