fix(tests): de-flake serve tests by isolating ports and failing fast - #2298
Draft
bhimrazy wants to merge 2 commits into
Draft
fix(tests): de-flake serve tests by isolating ports and failing fast#2298bhimrazy wants to merge 2 commits into
bhimrazy wants to merge 2 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.
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]:Test-only change; nothing under
litgpt/is touched.Root cause
All seven serve tests bind the hardcoded port
8000, and teardown never waits for the server to actually exit —kill_process_treeonly sends the signals, and the thread wrapping the non-blockingPopenwas joined instead of the process. That leads to 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 takes port 8000 with it.tensor_parallelruns last, so it inherits the debris.Changes
process.poll()while waiting, and fail immediately with the exit code plus a tail of the server output.NCCL_DEBUG=INFOon CI) before it binds.Verification
ruff checkandruff format --checkclean;pytest tests/test_serve.pypasses locally (GPU-gated tests skip).Server exited with code 2 before it was ready.with the server log, instead of a bare connection refused after 30s.Left as a draft: the 2-GPU
tensor_parallelpath can't be reproduced locally, so a few CI runs are the real confirmation.