Skip to content

chore(test): retry in scan_skips_camped_returns_free to avoid TOCTOU flake#150

Merged
StefanSteiner merged 1 commit into
tableau:mainfrom
StefanSteiner:fix/flaky-scan-test
Jun 16, 2026
Merged

chore(test): retry in scan_skips_camped_returns_free to avoid TOCTOU flake#150
StefanSteiner merged 1 commit into
tableau:mainfrom
StefanSteiner:fix/flaky-scan-test

Conversation

@StefanSteiner

Copy link
Copy Markdown
Contributor

Summary

Fixes a flaky test failure on macOS CI: scan_skips_camped_returns_free intermittently fails with expected FreePort, got Found(DaemonInfo { ... }).

Root cause: TOCTOU race — the test drops the base+1 port probe, sleeps 50ms, then scans. During that window, another parallel test's leaked HealthListener can bind base+1 and respond as a valid daemon.

Fix: Wrap the test in a retry loop (up to 5 attempts). If the scan returns Found because another test stole the port, pick a fresh port pair and try again (optimistic concurrency).

Test plan

  • cargo test -p hyperdb-mcp --test daemon_tests scan_skips_camped_returns_free passes locally
  • CI passes on all platforms (especially macOS where this was observed)

…flake

On macOS CI, other parallel tests' leaked HealthListeners can grab
the `base+1` port between our probe-drop and the scan, causing the
test to see `Found` instead of `FreePort`. Wrap the test body in a
retry loop (up to 5 attempts) so a stolen port triggers a fresh port
pair rather than a failure.
@StefanSteiner StefanSteiner merged commit eba615c into tableau:main Jun 16, 2026
12 checks passed
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