test(fetch,sample): bind to ephemeral port to fix flaky macOS CI#3827
Merged
Conversation
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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_fetch.rs(port 8081) andtests/test_sample.rs(port 8082) bind to hardcoded ports. On macOS GitHub runners this produces intermittentAddress 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.0(OS-assigned ephemeral) and thread the actual boundSocketAddrback to each test through the existingmpscchannel, so URLs are built against the real port at runtime.SampleWebServergains aurl(path)accessor;test_fetch.rsgets a smallstart_fetch_webserver()helper and runtimeformat!()URL construction in place of the oldtest_server!/test_url!concat!macros.Test plan
cargo check --tests -F all_features— cleancargo 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-existingzippotam.usskip)cargo clippy -F all_features --tests— 381 messages before and after; no new lints introducedmacOS - Polarspasses green on this PR🤖 Generated with Claude Code