Skip to content

Keep the refused-connection test from racing other tests - #187

Merged
Gorka Gonzalo (d0ubl3g) merged 1 commit into
devfrom
fix/flaky-connection-retry-test
Oct 15, 2026
Merged

Gorka Gonzalo (d0ubl3g) merged 1 commit into
devfrom
fix/flaky-connection-retry-test

Conversation

@d0ubl3g

Copy link
Copy Markdown
Contributor

Cause

a_connection_error_is_retried bound an ephemeral port, dropped the listener and expected connections to be refused. A parallel test (mockito binds ephemeral ports) could take that port in between, so the client got an answer and the retry count was not 2.

Fix

The listener stays bound for the whole test, so the port cannot be reused. It never accepts: each attempt times out (client timeout 200 ms), which the client retries like a connection error. Accept-and-close was not used because a reset after accept is not is_connect and would not be retried. Assertions are unchanged (Error::Transport, exactly 2 retries). The other bound listener in the file is kept alive until its thread is joined, so it needed no change.

Checks

  • cargo test -q -p hodeishield-api --test api 50 times in a loop: 0 failures.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --locked -- -D warnings and cargo test --workspace --locked pass.

Closes #183

a_connection_error_is_retried bound a listener on an ephemeral port,
dropped it and expected every connection to that port to be refused.
Between the drop and the client's attempts, another test running in
parallel (mockito servers bind ephemeral ports) could receive the same
port, so the client got an answer and the retry count was not 2.

The test now keeps the listener bound for its whole duration, so the
port cannot be reused. The listener never accepts, so each attempt
times out (short client timeout), which the client retries the same way
as a refused connection. A reset after accept would not be retried, as
it is not a connect error, so accepting and closing was not used. The
assertions are unchanged: Error::Transport and exactly 2 retries.

Closes #183

Signed-off-by: d0ubl3g <48954024+d0ubl3g@users.noreply.github.com>
@d0ubl3g
Gorka Gonzalo (d0ubl3g) merged commit e168f45 into dev Oct 15, 2026
20 checks passed
@d0ubl3g
Gorka Gonzalo (d0ubl3g) deleted the fix/flaky-connection-retry-test branch October 15, 2026 16:45
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