Skip to content

test(fetch,sample): bind to ephemeral port to fix flaky macOS CI#3827

Merged
jqnatividad merged 2 commits into
masterfrom
fix-flaky-tests-202605
May 7, 2026
Merged

test(fetch,sample): bind to ephemeral port to fix flaky macOS CI#3827
jqnatividad merged 2 commits into
masterfrom
fix-flaky-tests-202605

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

  • The actix-web test servers in tests/test_fetch.rs (port 8081) and tests/test_sample.rs (port 8082) bind to hardcoded ports. On macOS GitHub runners this produces intermittent Address already in use (os error 48) failures from peer integration-test binaries and TIME_WAIT sockets — e.g. run 25470381157, and similar flakes on master and other unrelated branches over the past day.
  • Switch both suites to port 0 (OS-assigned ephemeral) and thread the actual bound SocketAddr back to each test through the existing mpsc channel, so URLs are built against the real port at runtime. SampleWebServer gains a url(path) accessor; test_fetch.rs gets a small start_fetch_webserver() helper and runtime format!() URL construction in place of the old test_server! / test_url! concat! macros.

Test plan

  • cargo check --tests -F all_features — clean
  • cargo test -F all_features --test tests test_sample::sample_bernoulli_url -- --test-threads=1 — 4/4 passed × 4 consecutive runs (locally on macOS)
  • cargo test -F all_features --test tests test_fetch -- --test-threads=1 — 41 passed, 1 ignored (pre-existing zippotam.us skip)
  • cargo clippy -F all_features --tests — 381 messages before and after; no new lints introduced
  • CI: confirm macOS - Polars passes green on this PR

🤖 Generated with Claude Code

The test webservers in `tests/test_fetch.rs` (port 8081) and
`tests/test_sample.rs` (port 8082) were binding to hardcoded ports.
On macOS runners that produces intermittent "Address already in use"
failures from peer integration-test binaries and TIME_WAIT sockets,
e.g. https://github.com/dathere/qsv/actions/runs/25470381157.

Switch both to port 0 (OS-assigned ephemeral) and thread the actual
bound `SocketAddr` back to each test through the existing mpsc
channel, so URLs are built against the real port at runtime.

- `test_sample.rs`: drop `SAMPLE_TEST_PORT` and `sample_test_url`;
  `SampleWebServer` now stores the addr and exposes `url(path)`.
- `test_fetch.rs`: drop the `test_server!` / `test_url!` macros; add
  a `start_fetch_webserver()` helper; build URLs via runtime
  `format!()`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread tests/test_fetch.rs Dismissed
Comment thread tests/test_fetch.rs Dismissed
Comment thread tests/test_fetch.rs Dismissed
Comment thread tests/test_sample.rs Dismissed
Comment thread tests/test_fetch.rs Dismissed
Comment thread tests/test_fetch.rs Dismissed
Comment thread tests/test_sample.rs Dismissed
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 7, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

[skip ci]
@jqnatividad jqnatividad merged commit 8c646ca into master May 7, 2026
1 check was pending
@jqnatividad jqnatividad deleted the fix-flaky-tests-202605 branch May 7, 2026 03:48
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.

2 participants