test(python): remove fixed per-test delays from mock HTTP servers

The Python test jobs spend much of their pytest time waiting on the in-process mock HTTP servers.

1. Each server ran `serve_forever()` with the default 0.5 s poll interval, so every `server.shutdown()` blocked for up to 0.5 s. Around 300 tests use such a server (test_remote_db, test_authz/test_catalog, test_listing, the permutation helpers), about 150 s per test job on every platform. A shared `start_server_thread()` helper in `tests/utils.py` serves with a 0.01 s poll interval, so shutdown returns in about 10 ms.
2. The servers bind IPv4 only, but clients used `http://localhost:<port>`. The client tries ::1 first and falls back after the happy-eyeballs delay, about 0.3 s per connection on Windows. The mock handlers close the connection after each response, so one listing test took 9.5 s on Windows CI versus 0.6 s on Linux. Clients now use 127.0.0.1, as test_catalog, test_listing and test_namespace already do.

Measured on Windows with the 0.41.0b6 wheel and `-m "not slow and not s3_test"`: full suite 546.7 s to 212.3 s; test_remote_db.py, test_listing.py and test_catalog.py together 284 s to 14 s on current main. Collected test ids are identical (1898) and pass/fail/skip results match. No assertion, test or marker changed.
This commit is contained in:
max
2026-10-29 11:31:23 +08:00
committed by GitHub
parent 913ee160b0
commit 9ffd3d33e1
8 changed files with 60 additions and 62 deletions
@@ -15,7 +15,6 @@ import os
from pathlib import Path
import subprocess
import sys
import threading
import urllib.parse
from typing import Optional
@@ -34,6 +33,7 @@ from lancedb.functions import (
udf,
)
from lancedb.secrets import EnvVarSecret
from utils import start_server_thread
THRESHOLD = 20
_CACHE = None
@@ -295,13 +295,15 @@ class Handler(http.server.BaseHTTPRequestHandler):
self.wfile.write(payload)
server = http.server.ThreadingHTTPServer(("localhost", 0), Handler)
threading.Thread(target=server.serve_forever, daemon=True).start()
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
threading.Thread(
target=server.serve_forever, kwargs={"poll_interval": 0.01}, daemon=True
).start()
try:
db = lancedb.connect(
"db://dev",
api_key="API_KEY_SENTINEL",
host_override="http://localhost:%d" % server.server_address[1],
host_override="http://127.0.0.1:%d" % server.server_address[1],
client_config={"retry_config": {"retries": 0}},
)
db.create_secret("openai-prod", "SECRET_VALUE_SENTINEL")
@@ -1731,11 +1733,10 @@ def _mock_remote_function_catalog():
response = {"functions": []}
self._write_response(200, response)
with http.server.HTTPServer(("localhost", 0), Handler) as server:
thread = threading.Thread(target=server.serve_forever)
thread.start()
with http.server.HTTPServer(("127.0.0.1", 0), Handler) as server:
thread = start_server_thread(server)
try:
yield f"http://localhost:{server.server_address[1]}", state
yield f"http://127.0.0.1:{server.server_address[1]}", state
finally:
server.shutdown()
thread.join()