Repository navigation
Conversation
76054c5 to
b7dd358
Compare
|
@akx Thanks... I've shifted my development efforts over to this comprehensive redesign, due to it's significantly reduced complexity. Edit: Updated links. |
| finally: | ||
| server.should_exit = True | ||
| thread.join() | ||
| thread.join(timeout=timeout) |
There was a problem hiding this comment.
I think the timeout can still leave the test process hanging if server.run() gets stuck during startup.
The server thread is created as a non-daemon thread. If startup never completes, the timeout raises as expected, and the finally block waits for the thread for another timeout seconds. But if the thread is still blocked, join() returns while that non-daemon thread remains alive.
Python will then wait for the thread during interpreter shutdown, so the test process can still hang indefinitely.
I reproduced the underlying behavior with a blocked non-daemon worker: a timed join() returned, but the Python process stayed alive.
Could we ensure the server thread cannot keep the process alive after a startup timeout, perhaps by making it a daemon thread? A regression test with a deliberately stalled startup would help cover this case.
There was a problem hiding this comment.
Worth comparing the complexity here...
Lines 224 to 287 in b5addb6
vs. what we now have with hip...
@pytest.fixture
def server():
with hip.Server(echo) as server:
yield serverThere was a problem hiding this comment.
Thanks for the context. The HIP fixture is definitely much simpler and avoids much of the complexity involved in managing server threads manually.
My earlier comment was specific to the current HTTPX fixture, in case this PR is still being considered. I appreciate the clarification about the direction of development.
chiragjangiir
left a comment
There was a problem hiding this comment.
Code Review: Do not hang forever if test server fails to start
1. Issue Addressed
In the test suite, test servers (Server fixture) spin up in a background thread or process and wait on a readiness condition. If port binding failed (e.g., port collision in CI) or an unhandled exception occurred during startup, the test runner would block indefinitely waiting for server readiness.
2. Fix Details
- Adds a finite timeout (e.g., 5 seconds) to
server.wait_until_ready(). - Captures startup exceptions on the server thread and re-raises them in the main test thread if initialization fails.
- Prevents CI runners from timing out after 60+ minutes on flaky port allocations.
3. Recommendation
High-value improvement for developer experience and CI reliability. Approved.
Summary
I was wondering why the test suite just hung forever, and finally with
pytest tests/ -vvvx --log-cli-level=DEBUG -sI found that:– yep, I was working on something else on port 8000 – and so,
server.runningnever becomesTrue, and tests just hang.This PR:
server.run()(in the secondary thread) are caught and propagated immediately to the controlling loopChecklist