Skip to content

Commit 50a2183

Browse files
committed
chore: adopt run_uvicorn_in_thread from MAX-157, drop wait_for_server
Rebased onto MAX-157 (#2267) which landed run_uvicorn_in_thread with two improvements over the helper this branch had: - Pre-binds socket + listen() before thread start: port is known immediately, no polling loop, kernel queues early connections - interface="asgi3": skips uvicorn's asyncio.iscoroutinefunction autodetect, which Python 3.14 deprecates (cleaner than catch_warnings) Kept this branch's gc.collect() + ResourceWarning suppression in the finally — MAX-157's single WS smoke test didn't need it, but the SSE abrupt-disconnect test patterns here do. Also removed wait_for_server — MAX-155 (#2277) converted its last caller (test_integration.py) to in-memory transport.
1 parent a307bd7 commit 50a2183

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

tests/test_helpers.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import gc
44
import socket
55
import threading
6-
import time
76
import warnings
87
from collections.abc import Generator
98
from contextlib import contextmanager
@@ -68,30 +67,3 @@ def run_uvicorn_in_thread(app: Any, **config_kwargs: Any) -> Generator[str, None
6867
with warnings.catch_warnings():
6968
warnings.simplefilter("ignore", ResourceWarning)
7069
gc.collect()
71-
72-
73-
def wait_for_server(port: int, timeout: float = 20.0) -> None:
74-
"""Wait for server to be ready to accept connections.
75-
76-
Polls the server port until it accepts connections or timeout is reached.
77-
This eliminates race conditions without arbitrary sleeps.
78-
79-
Args:
80-
port: The port number to check
81-
timeout: Maximum time to wait in seconds (default 5.0)
82-
83-
Raises:
84-
TimeoutError: If server doesn't start within the timeout period
85-
"""
86-
start_time = time.time()
87-
while time.time() - start_time < timeout:
88-
try:
89-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
90-
s.settimeout(0.1)
91-
s.connect(("127.0.0.1", port))
92-
# Server is ready
93-
return
94-
except (ConnectionRefusedError, OSError):
95-
# Server not ready yet, retry quickly
96-
time.sleep(0.01)
97-
raise TimeoutError(f"Server on port {port} did not start within {timeout} seconds") # pragma: no cover

0 commit comments

Comments
 (0)