Skip to content

test(cli): wait for the server's own listening line and retry on a port race - #402

Merged
ajianaz merged 1 commit into
developfrom
test/serve-port-race
Oct 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
test/serve-port-race

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

What

Fix the intermittent tole serve test failures ("serve never became healthy") by making the spawn helpers race-free.

Why

serve_http_hardening failed about 1 run in 6 on develop. Reproduced and captured: the harness picks a port by binding 127.0.0.1:0 and closing it; before tole serve binds it, the same ephemeral port can be taken by another test's client socket. The server then exits with binding 127.0.0.1:52603 (in use? change --port): Address already in use and the health poll times out. The same pattern sits in four harnesses; serve_approvals also used fixed ports.

Changes

  • tests/common/mod.rs (new): spawn_listening builds the command for a candidate port, pipes its stderr, waits for the server's own "listening on" line (proof this process bound the port, not a stranger answering on it) and, if the process exits first, retries on a fresh port (5 attempts). Stderr is forwarded so it still appears in failure reports.
  • serve_http_hardening, mcp_http_hardening, serve_approvals (no more fixed ports) and serve_session_cancel use it.
  • A test for the helper itself: an instance that exits before listening is retried and the second one is used.

Testing

  • serve_http_hardening + mcp_http_hardening 15 times in a row: 0 failures (before: about 1 in 6). serve_approvals + serve_session_cancel 3 times: green.
  • fmt, clippy -D warnings, cargo test --workspace pass; cora review --staged clean.

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 6992b9f into develop Oct 16, 2026
17 checks passed
@ajianaz
ajianaz deleted the test/serve-port-race branch October 16, 2026 09:18
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