Skip to content

Do not wait forever for test server to start or stop#1037

Open
akx wants to merge 2 commits into
pydantic:mainfrom
akx:test-server-fix-hx2
Open

Do not wait forever for test server to start or stop#1037
akx wants to merge 2 commits into
pydantic:mainfrom
akx:test-server-fix-hx2

Conversation

@akx

@akx akx commented Jun 16, 2026

Copy link
Copy Markdown

Summary

I was wondering why the test suite just hung forever, and finally with pytest tests/ -vvvx --log-cli-level=DEBUG -s I found that:

[Errno 48] error while attempting to bind on address ('127.0.0.1', 8000): [errno 48] address already in use

– yep, I was working on something else on port 8000 – and so, server.running never becomes True, and tests just hang.

This PR:

  • Makes sure errors from server.run() (in the secondary thread) are caught and propagated immediately to the controlling loop
  • Adds timeouts, so even if something even more unexpected happens, the suite will error out instead of hanging forever.

Port of PR encode/httpx#3775

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
    • No separate tests for testing the test fixture 😄
  • I've updated the documentation accordingly.
    • No user-facing or developer documentation changes needed. (Noting that port 8000 must not be in use is a separate thing to maybe document, I think...)

Review in cubic

@codspeed-hq

codspeed-hq Bot commented Jun 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing akx:test-server-fix-hx2 (fac6261) with main (82b9e2d)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@mbeijen

mbeijen commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Thanks, but we already have #994 merged which makes sure the test select an available port instead of the overused port 8000

@akx

akx commented Jun 16, 2026

Copy link
Copy Markdown
Author

@mbeijen Great! The fix here is still relevant though: don't wait forever if there's an issue, and surface other exceptions :)

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.

2 participants