Skip to content

fix: harden integration tests against macOS port reuse races#840

Merged
ryanfowler merged 1 commit into
mainfrom
fix/macos-test-server-readiness-race
Jul 6, 2026
Merged

fix: harden integration tests against macOS port reuse races#840
ryanfowler merged 1 commit into
mainfrom
fix/macos-test-server-readiness-race

Conversation

@ryanfowler

Copy link
Copy Markdown
Owner

Summary

Fixes flaky compressed_sse_retry_drains_first_response_before_replay test on macOS CI.

Root Cause

macOS port reuse races when integration tests run in parallel — the test spawns a server thread and immediately calls run_fetch with no synchronization. The fetch binary gets ECONNREFUSED before the thread enters its accept loop.

Changes

  • tests/http.rs — Added mpsc readiness channels to two tests with manual TcpListener + thread patterns. The main thread now waits for the server thread to enter its accept loop before calling run_fetch/run_fetch_once.

  • tests/support/common.rs — Hardened run_fetch_opts retry loop: 4→9 retries with exponential backoff (25ms → 1s cap, ~3.6s total budget vs ~100ms before). This absorbs longer macOS kernel port-reuse delays.

Validation

  • cargo fmt --check
  • cargo clippy --locked --all-targets --all-features -- -D warnings
  • Full unit test suite ✅
  • All 37 http integration tests ✅
  • compressed_sse_retry_drains_first_response_before_replay passes locally ✅

Add readiness channels between server threads and the main thread in two
tests (compressed_sse_retry_drains_first_response_before_replay and
schemeless_https_connect_error_suggests_plaintext_url) so run_fetch is
not called until the server accept loop is running.

Increase run_fetch_opts transient-error retries from 4 to 9 with
exponential backoff (25ms → 1s cap) to absorb longer macOS kernel
port-reuse delays.
@ryanfowler ryanfowler enabled auto-merge July 6, 2026 17:13
@ryanfowler ryanfowler merged commit cdf2cc5 into main Jul 6, 2026
4 checks passed
@ryanfowler ryanfowler deleted the fix/macos-test-server-readiness-race branch July 6, 2026 17:17
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.

1 participant