Skip to content

refactor(udp-server): [#2699] gate the test environment behind a testing feature - #2711

Merged
josecelano merged 19 commits into
torrust:developfrom
josecelano:2699-2482-gate-udp-server-test-environment
Nov 4, 2026
Merged

josecelano merged 19 commits into
torrust:developfrom
josecelano:2699-2482-gate-udp-server-test-environment

Conversation

@josecelano

Copy link
Copy Markdown
Member

Closes #2699

Subissue 4 of sub-EPIC #2482 (row 4: gate the udp-server test environment), the first server environment to move behind a testing feature. The spec merged in #2700; the example decision is recorded there. The pattern is the one of row 3 (#2681).

What changes

  • udp-server: src/testing/ is compiled only with the new non-default testing feature (testing = ["dep:torrust-tracker-swarm-coordination-registry"]). That registry crate was the only direct dependency used solely by the module, so it is now optional; every other direct dependency has a production use.
  • udp-server's own targets (the src/ unit tests, tests/ and the examples) enable the feature through a path-only self dev-dependency (ADR option O1c), and axum-health-check-api-server enables it from its [dev-dependencies]. No [dependencies] entry or default chain enables testing.
  • deny.toml: torrust-tracker-udp-server is listed as its own wrapper, which the self dev-dependency requires; it is in the same commit as the manifest change, together with Cargo.lock.
  • Examples, as the maintainer decided on 2026-11-03: examples/udp_only_public_tracker.rs stays on the test environment and its header says it follows the testing conventions; a new examples/udp_only_public_tracker_production_style.rs starts the server the way the binary does (no testing module), and both headers explain the difference.
  • The inventory marks the udp-server part of pattern A resolved. The evidence is in manual-verification-evidence.md (V1 to V8), and there is an implementation retrospective.

Verification

  • A default udp-server build has no direct dependency on the registry crate (27 direct normal dependencies before, 26 after; it stays reachable through tracker-core and udp-core), and src/testing/ is absent from the default rustdoc output.
  • Test counts are equal before and after for udp-server (233 + 16 + 1 + 2), axum-health-check-api-server (15 + 8), axum-rest-api-server and rest-api-runtime-adapter, plain, with --all-features and with --all-targets --all-features; no required-features is used. Without its new dev-dependency feature the health check package fails to compile.
  • The Shipped Features check is green on the real tree and red (exit 1) with the feature on the root [dependencies] entry of udp-server or in its default chain. The shipped-profile binary has no test environment strings and the 35 cli-configuration tests pass with TORRUST_TRACKER_BINARY set to a preserved copy.
  • Both examples build under cargo test --examples and the nightly --all-features check, run under plain cargo run, answer a real UDP connect request and stop on SIGTERM.
  • cargo machete --with-metadata, cargo deny check bans (and red without the self wrapper), cargo +stable package --workspace --no-verify, the bench build and the pre-push script pass. An independent pre-PR review returned PASS WITH FINDINGS; its findings are fixed or answered in the evidence (V8).

Notes for reviewers

  • testing is public surface of a not yet published crate, outside semver; First publish of the unpublished workspace crates #2583 decides versions and this PR does not touch its spec.
  • The new example compiles through the self dev-dependency (it imports the optional registry crate), so a packaged crate needs --features testing to build it, like the src/ unit tests. The header explains the self dev-dependency.
  • The ADR still lists the example question as open; this PR records the decision in the spec and leaves any ADR amendment to the coordinator.
  • Rows 5 to 7 reuse the pattern, including the deny.toml self-wrapper entry and staging Cargo.lock with the manifest.

josecelano and others added 9 commits November 4, 2026 10:54
…a testing feature

Compile src/testing/ only with the non-default testing feature, make torrust-tracker-swarm-coordination-registry (used only by that module) optional behind it, and enable the feature for the package's own targets through a path-only self dev-dependency. The self dev-dependency gets its own deny.toml wrappers entry in the same commit.

Co-authored-by: Copilot <[email protected]>
…-server testing feature from its dev-dependencies

The health check contract tests start a UDP server through the test environment, which is now compiled only with the testing feature.

Co-authored-by: Copilot <[email protected]>
…following the testing conventions

Co-authored-by: Copilot <[email protected]>
…r example

The example starts the UDP server like the torrust-tracker binary does and does not use the testing feature, so the package keeps an example of production startup next to the testing-style one.

Co-authored-by: Copilot <[email protected]>
…r policy and loop error handling in the production-style example

Build the metrics policy from the UdpTracker configuration and the drain from Shutdown like the application does, report an io error of the receive loop, and word the header as not using the testing module (the registry crate it imports reaches the package's own targets through the self dev-dependency). The container composition and the listener stop move to helpers to keep main short.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 11:38
…ns and the decision

The container build strips workspace path dependencies from the third-party recipe but not the features that name them, so an optional workspace dependency behind the testing feature breaks it. Record the options with their strengths and weaknesses and the maintainer's choice (fix the cargo-chef fork and bump the pin), reopen the checkpoints and add tasks T6 to T8 and AC6.

Co-authored-by: Copilot <[email protected]>

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

2 open issues
What changed in this PR

This PR gates torrust-tracker-udp-server’s test environment behind a new non-default testing feature, making the test-only registry dependency optional and ensuring only test/consumer dev-targets opt into the feature.

Changes:

  • Add testing feature to udp-server, make torrust-tracker-swarm-coordination-registry optional, and gate pub mod testing behind #[cfg(feature = "testing")].
  • Enable testing via a path-only self dev-dependency for udp-server targets and via dev-dependency features in axum-health-check-api-server.
  • Update/add UDP examples and expand accompanying documentation/evidence to reflect the new “testing vs production-style” split.
File Description
packages/​udp-server/​src/​testing/​mod.rs Updates module docs to reflect gating behind testing feature.
packages/​udp-server/​src/​lib.rs Gates testing module export behind #[cfg(feature = "testing")].
packages/​udp-server/​examples/​udp_only_public_tracker_production_style.rs Adds a production-style example that starts the server without using the testing module.
packages/​udp-server/​examples/​udp_only_public_tracker.rs Updates example docs to explicitly describe “testing style” usage and the testing feature.
packages/​udp-server/​Cargo.toml Introduces testing feature, makes registry dependency optional, and adds a self dev-dependency enabling testing.
packages/​axum-health-check-api-server/​Cargo.toml Enables udp-server’s testing feature from dev-dependencies for tests.
docs/​pr-reviews/​pr-2711-review/​PR-REVIEW.md Adds PR review audit tracking document.
docs/​issues/​open/​2699-2482-gate-udp-server-test-environment/​manual-verification-evidence.md Adds detailed manual verification transcripts and evidence.
docs/​issues/​open/​2699-2482-gate-udp-server-test-environment/​implementation-retrospective.md Adds implementation retrospective and lessons learned.
docs/​issues/​open/​2699-2482-gate-udp-server-test-environment/​ISSUE.md Marks tasks/ACs as done and links evidence/PR metadata.
docs/​issues/​open/​2482-1669-reorganize-shared-test-support/​test-support-inventory.md Updates inventory to mark udp-server pattern A resolved and documents the new approach.
docs/​issues/​open/​2482-1669-reorganize-shared-test-support/​EPIC.md Updates EPIC row notes to reflect new example decision.
deny.toml Adds torrust-tracker-udp-server self-wrapper entry required by self dev-dependency pattern.

Review effort: Lite

josecelano and others added 2 commits November 4, 2026 12:18
…onal workspace dependencies

torrust-cargo-chef 0.1.79 prunes, in prepare --external-only, the feature entries that name a stripped path dependency. Without it the third-party cook stages fail on the testing feature of udp-server, whose registry dependency is optional. Do not push before 0.1.79 is published: cargo binstall cannot install it until then.

Co-authored-by: Copilot <[email protected]>
…nd the container recipe evidence

Co-authored-by: Copilot <[email protected]>
josecelano added a commit to torrust/cargo-chef that referenced this pull request Nov 4, 2026
…ped path dependency

ac66921 chore: bump torrust-cargo-chef to 0.1.79 (Jose Celano)
ff95e67 docs: document that --external-only prunes features of stripped dependencies (Jose Celano)
a4c95c3 fix(external-only): prune feature entries that name a stripped path dependency (Jose Celano)

Pull request description:

  `cargo chef prepare --external-only` removes `path = "..."` dependencies from every manifest, but it left the `[features]` entries that name them. An optional workspace dependency behind a feature is a valid and now planned pattern in `torrust/torrust-tracker` (`testing = ["dep:torrust-tracker-swarm-coordination-registry"]`, see torrust/torrust-tracker#2711). With the current `torrust-cargo-chef` 0.1.78 the skeleton manifest is then invalid and `cargo chef cook` exits with status 101:

  ```text
  failed to load manifest for workspace member `.../packages/udp-server`
    feature `testing` includes `dep:torrust-tracker-swarm-coordination-registry`, but `torrust-tracker-swarm-coordination-registry` is not listed as a dependency
  ```

  ## What changes

  - `src/skeleton/external_only.rs`: after stripping a manifest, prune the `[features]` entries that name a removed dependency: `dep:name`, `name` (the implicit feature of an optional dependency), `name/feature` and `name?/feature`. The feature itself is kept, possibly empty, so entries of other features that refer to it stay valid. A plain `name` that is also the name of a feature is kept (it then refers to the feature). Names removed from top-level, target-specific and `workspace = true` dependency tables count; `[workspace.dependencies]` names do not, because no feature can refer to them.
  - Tests first: six unit tests failed before the change (`dep:` entry, implicit entry, `name/feature` and `name?/feature`, `workspace = true` reference, target-specific dependency, plain entry that names a feature) next to control tests that passed; one skeleton integration test covers the failing shape end to end.
  - `CHANGELOG.md` and `README.md` describe the behaviour; the last commit bumps the version to 0.1.79 so the `Containerfile` of the tracker can pin it.

  ## Verification

  - `cargo test` passes in the whole crate (18 unit tests in the module, the skeleton and caching integration tests); `cargo fmt --check` passes. `cargo clippy --all-targets -- -D warnings` reports one error in `src/skeleton/read.rs` (`useless_borrows_in_formatting`), which is also present without this change and is not touched here.
  - On the real tracker tree (branch of torrust/torrust-tracker#2711, 2026-11-04 12:12 UTC): `torrust-cargo-chef` 0.1.78 `cargo chef prepare --external-only` then `cargo chef cook --tests --workspace --all-features` exits 101 with the message above; the build of this branch (0.1.79) writes `testing = []` in the skeleton of `udp-server` and the same `cook` exits 0.

  ## After merging

  Tag `v0.1.79-torrust` and publish `torrust-cargo-chef` 0.1.79; the tracker then bumps `[email protected]` in its `Containerfile`. Rows 4 to 7 of torrust/torrust-tracker#2482 need it.

ACKs for top commit:
  josecelano:
    ACK ac66921

Tree-SHA512: 47323365a7e761f7fd7e8e1ae3c067b87ed9070214364baa47eb1c6453a329ec1a2dcc77be040ff37a59ef693aff5227cd691dab104876c7a6cc501c0e2b1993
josecelano and others added 2 commits November 4, 2026 12:27
…e production-style example

A fixed file name in the shared temp directory collides across concurrent runs and leaves stale state after a crash.

Co-authored-by: Copilot <[email protected]>
…nd the container failure in the audit

Co-authored-by: Copilot <[email protected]>
@josecelano
josecelano requested a balanced review from Copilot November 4, 2026 12:34

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

3 open issues
2 resolved since last review

Review effort: Lite

Comment thread packages/udp-server/Cargo.toml Resolved
Comment thread packages/udp-server/src/testing/mod.rs Resolved
josecelano and others added 2 commits November 4, 2026 12:55
…n the production-style example helper

Co-authored-by: Copilot <[email protected]>
…rkspace rule, not a Cargo limit

Co-authored-by: Copilot <[email protected]>
…2 of the review and the completion

Co-authored-by: Copilot <[email protected]>
@josecelano

Copy link
Copy Markdown
Member Author

ACK 246617d

@josecelano
josecelano merged commit 905401f into torrust:develop Nov 4, 2026
25 checks passed
josecelano added a commit that referenced this pull request Nov 4, 2026
…ssues/closed

63a2462 docs(pr-reviews): [#2699] start the audit record of PR 2722 (Jose Celano)
c5273e9 chore(issues): archive closed issue #2699 spec to docs/issues/closed (Jose Celano)

Pull request description:

  Archives the spec for issue #2699 (closed on GitHub by the merge of PR #2711) from `docs/issues/open/` to `docs/issues/closed/`, and sets row 4 of the #2482 Subissues table to DONE.

  - Verified issue #2699 is `CLOSED` on GitHub (closed when PR #2711 merged, which carried the closing keyword for that issue)
  - Updated frontmatter (`status: done`, `spec-path`, `last-updated-utc`) and the last workflow checkpoint, and added the archive entry to the progress log
  - Repaired every live reference to the old `docs/issues/open/2699-...` path: the #2482 EPIC row and Progress Log, the inventory destination table, the subissue list of the 2026-10-06 coupling report, and the frontmatter of the evidence and the retrospective; a search for the old folder name finds nothing, and every relative link of the moved files resolves
  - The EPIC row 4 note and Progress Log record what rows 5 to 7 inherit: the `torrust-cargo-chef` 0.1.79 pin and the chef steps to run before their first push
  - Pre-commit hooks passed

ACKs for top commit:
  josecelano:
    ACK 63a2462

Tree-SHA512: 99d8a13d48ca84fd6d0a97ad3b89602d5a0a9dc2bc08ecf06feeecc4d37e65e3331126c94c09cc0d1fc8546a09ccd513f7b60e608cf7365850dc141adb71c525

@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.

This is a post-merge review of the change from #2711 as it stands at e170b9620 on the default branch.

What still runs: packages/udp-server/src/lib.rs:647 compiles the testing module only under the non-default testing feature, and that feature (packages/udp-server/Cargo.toml:23) is the only switch for the now-optional registry dependency (packages/udp-server/Cargo.toml:47). The package's own targets get the feature through the path-only self dev-dependency at packages/udp-server/Cargo.toml:62, the health check package gets it through its dev-dependency at packages/axum-health-check-api-server/Cargo.toml:53, and deny.toml:63-64 admits the self edge. Containerfile:28 keeps the 0.1.79 pin whose external-only recipe drops a feature that names a stripped path dependency. Both examples, the module header and the cfg attribute in lib.rs are byte-identical to the merged head 246617d1f.

[Minor] The production-style example leaves out jobs that the binary runs, and its header does not say so. packages/udp-server/examples/udp_only_public_tracker_production_style.rs:1-9 says it starts the tracker "the way the torrust-tracker binary starts it" and "simulates production as closely as possible", and names only two differences: it spawns the listeners itself and composes one instance. For the configuration the example builds (public, otherwise Core::default(), so usage statistics on and inactive_peer_cleanup_interval at 600 seconds), the binary also starts the UDP ban reset job (src/app.rs:480, every ip_bans_reset_interval_in_secs, 24 hours by default), the inactive-peer cleanup (src/app.rs:329), the peers inactivity update (src/app.rs:330) and the swarm registry and tracker-core statistics listeners (src/app.rs:321-322). The example starts none of them. Concretely, a client address that sends more than 10 requests with an invalid connection ID (the default max_connection_id_errors_per_ip) stays banned until the process exits, because only that job calls reset_bans (packages/udp-server/src/banning/mod.rs:42), and peers that stop announcing are never removed from their swarms. Anyone who takes the example as the production startup path of a UDP-only tracker inherits both. Smallest fix: name these omissions in the header next to the two it already lists, and say "the three UDP event listeners" so the count does not read as the full set. If the example should behave like the binary instead, spawn one loop that calls torrust_tracker_udp_server::banning::reset_bans every UdpTrackerServer::default().ip_bans_reset_interval_in_secs seconds and another that calls the tracker core container's torrents_manager.cleanup_torrents() every core.inactive_peer_cleanup_interval seconds, and cancel both before the listeners.

[Nit] The example exits 0 after a failed shutdown. At packages/udp-server/examples/udp_only_public_tracker_production_style.rs:162-177, a receive loop that returned Err or whose task panicked is reported with println!, then "Stopped." is printed and main returns normally; stop_event_listeners (line 210) does the same for a listener task that panicked. The binary treats the same outcomes as an incomplete shutdown and exits 1 (src/app.rs:170). Concretely, if the receive loop stops with a socket error before the signal arrives, a script that runs the example and checks its exit status sees a clean run. Smallest fix: have main return std::process::ExitCode, and return ExitCode::FAILURE when any join reports an error. To print those lines to standard error, also add clippy::print_stderr to the file's allow.

Checked and found sound:

  • No [dependencies] entry and no default chain enables testing anywhere in the workspace. The only entries that enable it are the two dev-dependencies above; the testing feature of axum-rest-api-server turns on the optional dependency but not its testing feature.
  • The shipped builds at Containerfile:174 and Containerfile:180 pass no test flag and no feature, and the Shipped Features job in .github/workflows/testing.yaml checks the torrust-tracker tree.
  • Outside the testing module, only the production-style example uses the registry crate, as its header says.
  • That example's container composition, start_with_cancellation arguments, per-instance metrics policy and stop order (receive loop first, then the listeners) match src/container.rs:80-116, src/bootstrap/jobs/udp_tracker.rs:71-83, src/bootstrap/jobs/udp_tracker_core.rs:17-21 and the stop-before edges at src/app.rs:655-661.
  • The example installs its Unix signal handlers before it prints readiness, binds to loopback only and names its temporary database per process.

This branch was previously deployed

1 inactive deployment
coverage — 246617d1 Deployed Nov 4, 2026 by josecelano via Generate Coverage Report #2913
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.

Gate the udp-server test environment behind a testing feature (#2482 subissue 4)

3 participants