Skip to content

test: [#2393] delete, rewrite and restore the tests ignored for port races - #2874

Merged
josecelano merged 15 commits into
torrust:developfrom
josecelano-bot:2393-implement-t5-port-race-tests
Nov 16, 2026
Merged

josecelano merged 15 commits into
torrust:developfrom
josecelano-bot:2393-implement-t5-port-race-tests

Conversation

@josecelano-bot

Copy link
Copy Markdown
Contributor

Closes #2393

Implements the T5 decisions recorded by the spec PR 2863 for the twenty-one tests that PR 2859 disabled with #[ignore = "flaky port race, see #2393"]. After this PR no test is ignored for #2393 on Linux.

Summary

  • T7: delete 9. The testing environment tests that only checked that test-support code frees its ports are removed.
  • T8: rewrite 3. The health-check API contract tests no longer start and stop a real service, which released its port for other tests to take. Each registers the service's production health check (check_fn of the REST API and HTTP tracker, Launcher::check of the UDP tracker) against an address the test holds for the whole test: a TCP socket bound and never listening refuses the check, and a held UDP socket never answers it, so the check times out. The tests are renamed for the state they set up (…refuses_the_check, …never_answers_the_check); every assertion on the report is unchanged.
  • T9: restore 9. A new helper, torrust_tracker_test_helpers::random::loopback_ipv4(), returns a random 127.a.b.c address with each octet in 1..=254, never 127.0.0.1. The nine tests that prove a socket is released by rebinding its address now choose that address on a random loopback address, so another test that binds 127.0.0.1:0 and receives the released port no longer blocks the rebind. They run on Linux and are ignored on other systems with #[cfg_attr(not(target_os = "linux"), ignore = "needs the Linux 127.0.0.0/8 loopback range, see #2393")], since macOS and the BSDs configure only 127.0.0.1. The restored tests cover the HTTP tracker, REST API and health-check API registration failures, the UDP server's cancellation, registration failure and orphaned request processors, the UDP tracker and health-check API components dropped before they run, and the application's later HTTP startup failure.

No production code changes.

Files touched

  • packages/test-helpers/src/random.rs: the loopback helper and its two tests.
  • packages/axum-health-check-api-server/tests/server/contract.rs: the three rewritten contract tests and their helpers.
  • packages/axum-http-server/src/server.rs, packages/axum-rest-api-server/src/server.rs, packages/axum-health-check-api-server/src/server.rs: the registration-failure tests.
  • packages/udp-server/src/server/mod.rs, packages/udp-server/src/server/launcher.rs: the UDP release tests. The launcher's shared test fixture now takes its bind address per scenario.
  • src/bootstrap/jobs/udp_tracker.rs, src/bootstrap/jobs/health_check_api.rs, src/app.rs: the component and startup release tests.
  • packages/axum-health-check-api-server/src/environment.rs, packages/axum-http-server/src/testing/environment.rs, packages/axum-rest-api-server/src/testing/environment.rs, packages/udp-server/src/testing/environment.rs: the deleted testing environment tests (T7).
  • docs/issues/open/2393-2392-test-port-allocation-races/: the spec (T7 to T10 done, acceptance criteria, completion review) and the evidence (V5, V6, V7).

Validation

  • Red then green (V5): for each rewritten or restored test, the guarded cleanup was removed in the production code (or the probed address made to answer), the test failed on its own assertion, and only the tests that guard that cleanup failed. Each group then passed 20 of 20 runs.
  • Design review (V7): a prose-first Arrange-Act-Assert review per increment, following the write-unit-test skill. The maintainer reviewed the T8 and T9 tests before the recheck.
  • Full recheck (V6): 150 of 150 runs of cargo nextest run --tests --all-features --no-fail-fast passed with 1844 tests and 0 skipped, plus one run of 1848 tests after the rebase onto develop. git grep 'see #2393' -- '*.rs' finds only the non-Linux cfg_attr lines.
  • linter all exits with 0, the pre-commit checks passed on every commit, and the pre-push checks passed on each push.

Notes

🤖 Generated with Claude Code

josecelano-bot and others added 8 commits November 16, 2026 08:22
…release tests

They checked that the `testing` feature's environments free their ports, which is
test-support code, not tracker behavior. Every user of these environments binds
port 0, so nothing depends on it (T7 of the torrust#2393 spec).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the failing-check contract tests

The three contract tests started and stopped a real service, and the stop released
its port for other tests to take. Each now registers the service's production health
check against an address the test holds for the whole test: a TCP socket bound and
never listening refuses the check, and a held UDP socket never answers it. The tests
run again and are renamed for the state they set up (T8 of the torrust#2393 spec), with the
red-then-green check (V5) and the design review (V7) recorded in the evidence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`random::loopback_ipv4` returns `127.a.b.c` with each octet in 1..=254, never
127.0.0.1. A test that rebinds a port after the code under test releases it can bind
port 0 on this address, so another test that binds 127.0.0.1:0 and receives the
released port no longer blocks the rebind. Linux only; its port-sharing test is
ignored on other systems. Red-then-green (V5) and the design review (V7) are recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er release tests

The HTTP tracker, REST API and health-check API tests that prove a failed
registration releases the listener chose a port on 127.0.0.1, released it, and
rebound it, so any test binding 127.0.0.1:0 could take it in between. They now
choose the address with `random::loopback_ipv4` and run again on Linux; other
systems ignore them. Red-then-green (V5) and the design review (V7) are recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The cancellation, registration-failure and orphaned-processor tests rebind the UDP
server's address after it is released, so a test binding 127.0.0.1:0 could take the
port in between. They now bind a random loopback address and run again on Linux;
other systems ignore them. The cancellation test also starts on port 0 instead of a
released address. Red-then-green (V5) and the design review (V7) are recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ease tests

The UDP tracker and health-check API job tests that drop an unpolled component, and
the application test whose HTTP start fails after the UDP tracker started, chose
their address on 127.0.0.1, released it, and rebound it later. They now choose it on
a random loopback address and run again on Linux; other systems ignore them.
Red-then-green (V5) and the design review (V7) are recorded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…letion review

All 150 full-suite runs passed with none of the torrust#2393 tests skipped, and the
source check finds `see torrust#2393` only in the non-Linux `cfg_attr` (V6). Marks T9 and
T10 done, ticks the acceptance criteria, and records the implementation
completion review. T11 waits for this PR to merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
da2ce7
da2ce7 previously approved these changes Nov 16, 2026

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 314f58775608baed0e1fb39f9a65d791497f207f. Recomputed from the bytes at this head, against the merge base a35960402; git merge-tree against develop 1c3daab4b writes a clean tree, and in the two files both sides touch (src/app.rs, src/bootstrap/jobs/health_check_api.rs) the merged tree keeps the restored tests on their random loopback helpers and the same ten cfg_attr lines.

Process: a test change governed by write-unit-test, with the fix-bug red-then-green the spec requires, and commit-changes and open-pull-request for history and description. The commits follow the spec's commit points, and each test commit carries its V5 and V7 entries.

The change against its claim: the merge base has 21 flaky port race, see #2393 ignores and this head has none. see #2393 appears only in ten non-Linux cfg_attr lines: the nine restored tests and the helper's port-sharing test. Every caller of a helper that now binds random::loopback_ipv4() is one of those ten tests. The three contract rewrites keep every report assertion, and check_fn and Launcher::check are public and match the registration's function type. The deletions leave no unused import or helper. The 1844 to 1848 count after the rebase matches the four tests packages/primitives gained in the base.

Consistency: the M1 to M7 evidence anchors and the in-file anchor resolve, and the dictionary is unchanged.

Hygiene: eight commits with Conventional subjects carrying [#2393], and author equals committer. Each has one attribution footer, which no rule in the tree forbids (its discussion records no decision). git diff --check is clean, the skill's commit-id check prints nothing, and the description's only closing keyword is Closes #2393.

Findings: F1 to F3 Minor, F4 and F5 Nit, F6 Suggestion; none blocks. F1 dates a run after the commit that records it, F2 and F3 are claims the evidence does not carry.

Checked, no finding: the nine deletions match the T5 table; no production code changes; the launcher companion keeps 127.0.0.1; new lines fit rustfmt's width.

Checks

On the loop's compute node at this head, against the merge base a35960402 (receipt server-gates-kranich-931): the repository's pre-commit gate and lint roster exit 0 (190 s wall). This PR has no audit record, so the gate ran no validator for it. The tests of the packages the PR touches (axum-health-check-api-server, axum-http-server, axum-rest-api-server, test-helpers, udp-server and the root crate) pass at this head: 884 passed, 0 failed, 1 ignored across 33 binaries (99.3 s wall); the one ignored test is the udp-server statistics doctest, and no #[ignore] attribute remains in those packages. F1 checked against the bytes at posting: line 274 of manual-verification-evidence.md stamps the run 2026-11-16 08:35 UTC, while the commit that adds it is dated 08:23:00Z. GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-axum-rest-api-server): completed/success; Package Coverage (torrust-tracker): in_progress/pending; Package Coverage (torrust-tracker-udp-server): completed/success; Package Coverage (torrust-tracker-test-helpers): completed/success; Package Coverage (torrust-tracker-axum-http-server): completed/success; Package Coverage (torrust-tracker-axum-health-check-api-server): completed/success; Docker E2E: completed/skipped; Build on windows-latest (nightly): completed/success; Build on macos-latest (stable): completed/success; Layer Boundary Bans: completed/success; Unit (nightly): completed/success; Unit (stable): completed/success; Shipped Features: completed/success; Build on ubuntu-latest (nightly): completed/success; Workspace Packaging: completed/success; Build on ubuntu-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Documented Clippy Allows: completed/success; Build on windows-latest (stable): completed/success; Discover Package Coverage: completed/success; Generate Coverage Report: completed/success; Docs Lint: completed/success; Test (Docker) (release): in_progress/pending". At posting, develop is a25a27e23.

Comment thread packages/axum-http-server/src/server.rs Resolved
@da2ce7

da2ce7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

ACK 314f587 — the 21 port-race ignores recomputed to zero with ten non-Linux cfg_attr lines, every random-loopback caller confined to them, and a clean merge-tree against develop

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

Updates previously-ignored/flaky port-release tests for #2393 by deleting low-value release tests, rewriting health-check contract tests to avoid starting/stopping real services, and restoring release/rebind tests on Linux using randomized loopback IPs to prevent cross-test port handoffs.

Changes:

  • Added torrust_tracker_test_helpers::random::loopback_ipv4() (+ unit tests) and switched several release/rebind tests to bind on random 127.0.0.0/8 addresses.
  • Rewrote axum health-check contract tests to register production health checks against “refusing/silent” sockets held by the test.
  • Deleted multiple previously-ignored “testing environment releases its port” tests; updated docs/spec evidence to mark T7–T10 done.
File Description
src/​bootstrap/​jobs/​udp_tracker.rs Uses random loopback address selection for UDP socket-release test; Linux-only ignore gating.
src/​bootstrap/​jobs/​health_check_api.rs Uses random loopback address selection for listener-release test; Linux-only ignore gating.
src/​app.rs Uses random loopback address selection for UDP reservation in startup failure test; Linux-only ignore gating.
packages/​udp-server/​src/​testing/​environment.rs Removes ignored UDP environment release tests (T7 deletions).
packages/​udp-server/​src/​server/​mod.rs Updates UDP server release tests to avoid 127.0.0.1 port races; Linux-only ignore gating; reads bound address back.
packages/​udp-server/​src/​server/​launcher.rs Refactors launcher test fixtures to take bind address per scenario; uses random loopback for orphaned-processor release test.
packages/​test-helpers/​src/​random.rs Adds loopback_ipv4() helper and tests validating range + Linux-only port-sharing property.
packages/​axum-rest-api-server/​src/​testing/​environment.rs Removes ignored REST API environment release tests (T7 deletions).
packages/​axum-rest-api-server/​src/​server.rs Uses random loopback for registration-failure release test; Linux-only ignore gating.
packages/​axum-http-server/​src/​testing/​environment.rs Removes ignored HTTP environment release tests (T7 deletions).
packages/​axum-http-server/​src/​server.rs Uses random loopback for registration-failure release test; Linux-only ignore gating.
packages/​axum-health-check-api-server/​tests/​server/​contract.rs Rewrites contract tests to probe refusing/silent sockets held for the test lifetime; adds helpers for registration/startup.
packages/​axum-health-check-api-server/​src/​server.rs Uses random loopback for registration-failure release test; Linux-only ignore gating.
packages/​axum-health-check-api-server/​src/​environment.rs Removes ignored health-check API environment release & fixed-port restart tests (T7 deletions).
docs/​issues/​open/​2393-2392-test-port-allocation-races/​manual-verification-evidence.md Adds V5/V6/V7 evidence; updates timestamps and follow-up notes.
docs/​issues/​open/​2393-2392-test-port-allocation-races/​ISSUE.md Marks T7–T10 + acceptance criteria items as DONE; adds completion notes.

Review effort: Lite

Comment thread packages/test-helpers/src/random.rs Resolved
Comment thread src/app.rs Resolved
josecelano-bot and others added 5 commits November 16, 2026 08:52
…ed service through the shared helper

`registar_with_a_probed_service` repeated the body of `registar_with_one_service`.
It now calls that helper with its fixed binding and role, so the contract tests
have one registration path (review finding F6 on PR 2874).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…leased test address

T9 rewrote the comment of `available_http_bind_address` and dropped the warning
against retries or waits. A socket bound to `0.0.0.0` on the same port can still
take the address, so the warning still applies (review finding F5 on PR 2874).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ntainer review and repeated green runs

Review findings F1 to F4 on PR 2874. The post-rebase run is stamped with the
interval between the rebased commit and the commit that records it, and the
previous progress-log entry with its commit's author time, instead of guessed
times. V5 records 20 of 20 green runs for T8 and the loopback helper, V7 records
the maintainer's review of the final increment, AC7 points at it, and the last
acceptance criterion is ticked with its evidence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…commit time

The previous commit stamped its progress-log entry and both `last-updated-utc`
fields 08:57, later than its own author time (08:55:12 UTC), the same mistake
review finding F1 on PR 2874 reported. They now carry 08:55.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Records the six findings of da2ce7's first review (F1 to F6), their fixes and
the reply URLs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
josecelano-bot and others added 2 commits November 16, 2026 09:02
…ped address

`hold_a_tcp_address_that_refuses_connections` parsed "127.0.0.1:0" and unwrapped
the result. It now builds the address from `Ipv4Addr::LOCALHOST` and port `0`, so
the helper has no parse step that could panic (review finding F9 on PR 2874).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in the PR 2874 audit

Adds the four findings of Copilot's first review: F9 fixed, F7, F8 and F10 kept
with the reasons given in their replies. The log records that their threads were
first resolved by mistake before they were answered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@josecelano

Copy link
Copy Markdown
Member

ACK 98c241c

@josecelano
josecelano requested review from da2ce7 and a balanced review from Copilot November 16, 2026 09:07

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 98c241c5748cb33011e1e1d2ac5e85143187c61d. Recomputed from the bytes at this head, against the merge base a35960402; git merge-tree against develop a25a27e23 writes a clean tree. Since round 1, develop gained only a docs merge, and the files both sides touch are the same two as then.

Since round 1 (314f58775), the seven new commits each match their message. F1 to F6 are fixed:

  • F1: the post-rebase run is dated by the commit times around it, and the earlier log entry is restamped.
  • F2: the evidence records 20 of 20 repeated greens for T8 and the helper, and the quoted nextest totals match the 24 and 2 tests of those packages.
  • F3: the V7 entry that AC7 now names is added.
  • F4: the criterion is ticked with its evidence.
  • F5: the guard is restored and names the 0.0.0.0 risk.
  • F6: the readiness helper calls the shared one.

5fdbab2e4 binds the held TCP socket to SocketAddr::from((Ipv4Addr::LOCALHOST, 0)). That is the same address as before, without the parse step, so the tests behave as they did.

Audit record: ten rows, one per inline thread of the two reviews on the last audited head. Each row's reply sits on its own thread, and all ten threads are resolved. I ran the validator's logic offline on the captured comments and the PR's commit subjects, and it passes (10 rows, 3 log entries, 0 failures). The three no-change dispositions give sound reasons: a cfg gate would break the macOS and Windows builds, the temporary outlives the call, and the helpers differ in shape. The log records the early mis-resolution and its correction.

Hygiene: Conventional subjects carrying [#2393], and author equals committer. Each commit has one attribution footer, which no rule in the tree forbids. git diff --check is clean, the commit-id check prints nothing, and no commit message carries a closing keyword.

Findings: none new.

Checked, no finding: the head still has no flaky port race ignore and ten cfg_attr lines, and the new chain fits rustfmt's width.

Checks

On the loop's compute node at this head, against the merge base a35960402 (receipt server-gates-kranich-940): the repository's pre-commit gate and lint roster exit 0 (133 s wall), and the review-audit validator reports 10 rows, 3 log entries and no failure. The torrust-tracker-axum-health-check-api-server package tests pass at this head: 24 passed, 0 failed across 3 binaries (29.7 s wall); at ef0490f73 that package and torrust-tracker-axum-http-server passed 135. Checked against the bytes at posting: no flaky port race ignore remains in the tree, and the ten cfg_attr(not(target_os = "linux"), ignore = …) lines all cite the Linux loopback range and #2393. GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-udp-server): completed/success; Package Coverage (torrust-tracker): in_progress/pending; Package Coverage (torrust-tracker-axum-health-check-api-server): completed/success; Package Coverage (torrust-tracker-axum-rest-api-server): completed/success; Package Coverage (torrust-tracker-test-helpers): completed/success; Package Coverage (torrust-tracker-axum-http-server): completed/success; Build on windows-latest (stable): completed/success; Build on macos-latest (stable): completed/success; Build on ubuntu-latest (stable): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (nightly): completed/success; Build on ubuntu-latest (nightly): completed/success; Docs Lint: completed/success; Generate Coverage Report: completed/success; Discover Package Coverage: completed/success; Test (Docker) (release): in_progress/pending; Docker E2E: completed/skipped; Workspace Packaging: completed/success; Unit (nightly): completed/success; Documented Clippy Allows: completed/success; Shipped Features: completed/success; Layer Boundary Bans: completed/success; Unit (stable): completed/success". At posting, develop is a25a27e23.

@da2ce7

da2ce7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

ACK 98c241c — F1 to F6 recomputed as fixed, the typed held-socket bind read as code, and all ten review threads replied, recorded and resolved with the audit validator's logic passing offline

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josecelano

Copy link
Copy Markdown
Member

ACK 98c241c

@josecelano
josecelano merged commit 4cae72c into torrust:develop Nov 16, 2026
27 checks passed
josecelano added a commit that referenced this pull request Nov 16, 2026
… mark it DONE in EPIC #2392

affdcc1 docs(pr-reviews): [#2393] record Copilot's re-raise of F7 in the PR 2883 audit (josecelano-bot)
57eb8ac docs(pr-reviews): [#2393] cite F6's fix by its reply in the PR 2883 audit (josecelano-bot)
a34c277 docs(pr-reviews): [#2393] record da2ce7's second-round findings in the PR 2883 audit (josecelano-bot)
1a5f7d1 docs(issues): [#2392] give the restored tests' non-Linux ignore the spec's reason (josecelano-bot)
1574471 docs(pr-reviews): [#2393] add the PR 2883 review audit (josecelano-bot)
61e30a9 docs(issues): [#2392] name the restored tests' loopback address the way the EPIC does (josecelano-bot)
55a3672 docs(issues): [#2393] state the T11 close-out in the past tense (josecelano-bot)
0b2c66c docs(issues): [#2392] mark Phase 1 done and sync AC2 and the coverage risk with #2393 (josecelano-bot)
c88dfbc docs(issues): [#2393] stamp the archive entries with the archive commit time (josecelano-bot)
3afe68c chore(issues): [#2393] archive the closed issue spec and mark it DONE in EPIC #2392 (josecelano-bot)

Pull request description:

  Close-out (T11) for #2393, which PR #2874 closed.

  - Verified #2393 is `CLOSED` on GitHub.
  - Moved `docs/issues/open/2393-2392-test-port-allocation-races/` to `docs/issues/closed/`, set `status: done`, the new `spec-path`/`issue-spec` and `last-updated-utc`, set T11 to DONE and logged the archive.
  - EPIC #2392: order 1 set to DONE with its outcome (PRs #2859 and #2874, 150 of 150 full-suite runs with no #2393 test ignored, #2867 found along the way), path updated, progress log entry added.
  - #2394's spec: link updated to the new path.
  - Past PR review records (`docs/pr-reviews/pr-2859-review/`, `pr-2863-review/`) keep the old path as a historical record.
  - Pre-commit checks passed.

  **History rewritten:** for review finding F2, the first commit's body was reworded to drop a closing keyword; its tree is unchanged. The head that the first review round and its ACKs cite is that commit, `chore(issues): [#2393] archive the closed issue spec and mark it DONE in EPIC #2392`, before the reword. The review fixes follow it as separate commits.

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

ACKs for top commit:
  josecelano:
    ACK affdcc1
  da2ce7:
    ACK affdcc1 — F4 to F6 recomputed as fixed, all nine threads replied, recorded and resolved with the audit validator's logic passing offline; one non-blocking finding on the pre-reword commit id

Tree-SHA512: d921fdafb9aeff30a1762d9482642cfe83030fd5c6554c92470c29dbb5d5f7431ed0e8d831157f1b9ee9932bc1319a8b07a7c2caf483008be79057b32f25ff18

This branch was previously deployed

1 inactive deployment
coverage — 98c241c5 Deployed Nov 16, 2026 by josecelano-bot via Generate Coverage Report #3208
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.

Eliminate parallel test port allocation races

4 participants