Skip to content

Wait for UDS test server readiness instead of a fixed 1.5s sleep - #914

Open
vyrnsynx wants to merge 1 commit into
emmett-framework:masterfrom
vyrnsynx:fix/uds-test-readiness-855
Open

vyrnsynx wants to merge 1 commit into
emmett-framework:masterfrom
vyrnsynx:fix/uds-test-readiness-855

Conversation

@vyrnsynx

@vyrnsynx vyrnsynx commented Sep 2, 2026

Copy link
Copy Markdown

Problem

tests/test_uds.py spawned Granian and then slept a fixed 1.5 seconds before issuing HTTP requests over the Unix domain socket. On slower machines the UDS listener is often not accepting connections yet, so httpx fails with ConnectError. Fast machines paid the full 1.5s wait even when the socket was already ready.

This is a test-side race: the socket file can exist after bind while listen() has not completed.

Change

Replace asyncio.sleep(1.5) with _wait_until_uds_ready(), which polls until a connect to the UDS succeeds. It returns as soon as the listener accepts a connection, times out after 30 seconds with a clear error, and fails early if the server process exits before the socket is ready. A leftover socket file is treated as not ready (connect must succeed).

Helper coverage (no Granian process required):

  • Returns quickly when a listener is already up
  • Times out when nothing is listening
  • Times out when only a stale socket file exists
  • Polls until a delayed bind/listen completes

Production server behavior is unchanged.

How tested

  • make format / make lint-python
  • make build-dev
  • pytest -v tests/test_uds.py (20 passed)

Fixes #855

tests/test_uds.py slept 1.5s after spawning the server. On slower
hosts the listener was not ready yet, so httpx hit ECONNREFUSED.
Poll until the Unix socket accepts a connection (with a timeout) so
fast machines return immediately and slow ones wait as needed.

Fixes emmett-framework#855

Co-authored-by: MarkGus0 <MarkGus0@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Tests in tests/test_uds.py fail with httpx.ConnectError: [Errno 111] Connection refused

1 participant