fix(tests): de-flake serve tests by isolating ports and failing fast - #2298
Open
bhimrazy wants to merge 6 commits into
Open
fix(tests): de-flake serve tests by isolating ports and failing fast#2298bhimrazy wants to merge 6 commits into
bhimrazy wants to merge 6 commits into
Conversation
The serve tests all bound the hardcoded port 8000 and killed the server without waiting for the process tree to exit, so a server that was still shutting down made the next one exit at bind time with 'Address already in use'. The test then polled a dead server for 30s and reported a bare connection error with no log. A failing test leaked its server entirely, because the assertion fired before the line that killed it. - serve on a free port per test - stop polling as soon as the server process exits, and report its exit code and log tail instead of a generic connection error - always kill the server, and wait for its process tree to exit - log to a file rather than to a pipe that nothing reads during startup - allow 120s for startup, which is cheap now that a dead server fails fast - drop the thread wrapper around the non-blocking Popen and share the checkpoint and server setup between the tests
Keep reporting the actual exception text (e.g. connection refused) when the server never answers, instead of a generic status placeholder, matching what the old _wait_and_check_response reported.
- probe the free port on all interfaces, matching the server's 0.0.0.0 bind, so a port taken elsewhere is not reported as free - report the status code when the server answers with something other than 200 - explain the teardown wait by what it actually protects now that ports are unique: GPU memory and lingering workers - trim the comments down to the non-obvious mechanics - drop text=True, which does nothing when stdout is a file and no pipe is read
bhimrazy
marked this pull request as ready for review
August 21, 2026 08:51
bhimrazy
requested review from
andyland,
k223kim,
lianakoleva and
t-vi
as code owners
August 21, 2026 08:51
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.
What does this PR do?
Fixes the recurring flake in
tests/test_serve.py, most often seen ontest_serve_with_generate_strategy[tensor_parallel]:Each test now serves on its own OS-assigned free port, so servers can no longer collide:
Server exited with code 2 before it was ready.right away, rather than a connection refused after 30s.NCCL_DEBUG=INFOon CI) before it binds.Root cause
All seven tests bound the hardcoded port
8000, and teardown never waited for the server to actually exit —kill_process_treeonly sends the signals, and the thread wrapping the non-blockingPopenwas joined instead of the process. Three compounding problems:bind_socket()via uvicorn's silentsys.exit(1), which the test can only observe as a connection refused.kill_process_treecall below it is never reached, so the server survives for the rest of the session and keeps port 8000.tensor_parallelruns last, so it inherits the debris.