You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test: fix flaky deadline tests of the HTTP client #815
Two tests in tests/utils/test_http.py fail now and then in CI and pass on re-run, which blocks merges:
test_address_fallback_bounded fails with assert 0 == 1 (seen in at least three runs on 2026-11-21, all on Python 3.15, e.g. run 44869902896, run 44875077790).
test_deadline fails with DeadlineExceeded: No time left to connect to 127.0.0.1 instead of the expected RequestMaybeSent (read_timeout).
Cause
Both tests give a request a real-time budget of 80 to 100 ms and expect the client to reach the connect step within it. On a slow or busy runner (coverage tracing, debug logging, background threads), the client's own work before connecting (preparing the request, opening the pool) can take longer, so the budget is gone before the first connect attempt:
test_deadline: the request ends with DeadlineExceeded before it is sent, so it never reaches the read that should time out.
test_address_fallback_bounded: the second request (timeout=0.08) has no time left for its first address, so no connect attempt is recorded (0), instead of one.
Injecting 0.1 s of overhead before connecting (patching requests.Session.prepare_request to sleep) reproduces both failures deterministically. With 0.3 s, test_deadline_bounds_reads (0.3 s deadline) fails the same way.
Fix
Make the tests deterministic without weakening them:
test_address_fallback_bounded: use a fake clock in foca.utils.http, which the fake connect advances, so the shared connect budget is exact.
test_deadline, test_deadline_bounds_reads: give the deadline enough room for connecting, against a server that holds the response until the client gives up, so that only the read can hit the deadline.
Activity