Skip to content

test: fix flaky deadline tests of the HTTP client #815

Closed

Description

@uniqueg

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

  1. self-assigned this
    on Nov 22, 2026
  2. added
    priority: high
    status: in progress
    type: testing
    workload: hours
    on Nov 22, 2026
  3. moved this from Backlog to In progress in ELIXIR On-Cloudon Nov 22, 2026
  4. moved this from In progress to In review in ELIXIR On-Cloudon Nov 22, 2026
  5. moved this from In review to Done in ELIXIR On-Cloudon Nov 22, 2026
  6. removed
    status: in progress
    on Nov 23, 2026
  7. added this to the v0.23.0 milestone on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: hightype: testingworkload: hours

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions