Repository navigation
refactor(udp-server): [#2699] gate the test environment behind a testing feature - #2711
Conversation
…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]>
Co-authored-by: Copilot <[email protected]>
…ttern A resolved 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]>
… and the pre-PR review Co-authored-by: Copilot <[email protected]>
…rospective Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…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]>
There was a problem hiding this comment.
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
testingfeature toudp-server, maketorrust-tracker-swarm-coordination-registryoptional, and gatepub mod testingbehind#[cfg(feature = "testing")]. - Enable
testingvia a path-only self dev-dependency forudp-servertargets and via dev-dependency features inaxum-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
…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]>
…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
…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]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
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
…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]>
|
ACK 246617d |
…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
left a comment
There was a problem hiding this comment.
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 nodefaultchain enablestestinganywhere in the workspace. The only entries that enable it are the two dev-dependencies above; thetestingfeature ofaxum-rest-api-serverturns on the optional dependency but not itstestingfeature. - The shipped builds at
Containerfile:174andContainerfile:180pass no test flag and no feature, and theShipped Featuresjob in.github/workflows/testing.yamlchecks thetorrust-trackertree. - Outside the
testingmodule, only the production-style example uses the registry crate, as its header says. - That example's container composition,
start_with_cancellationarguments, per-instance metrics policy and stop order (receive loop first, then the listeners) matchsrc/container.rs:80-116,src/bootstrap/jobs/udp_tracker.rs:71-83,src/bootstrap/jobs/udp_tracker_core.rs:17-21and the stop-before edges atsrc/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.



Closes #2699
Subissue 4 of sub-EPIC #2482 (row 4: gate the
udp-servertest environment), the first server environment to move behind atestingfeature. 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-defaulttestingfeature (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 (thesrc/unit tests,tests/and the examples) enable the feature through a path-only self dev-dependency (ADR option O1c), andaxum-health-check-api-serverenables it from its[dev-dependencies]. No[dependencies]entry ordefaultchain enablestesting.deny.toml:torrust-tracker-udp-serveris listed as its own wrapper, which the self dev-dependency requires; it is in the same commit as the manifest change, together withCargo.lock.examples/udp_only_public_tracker.rsstays on the test environment and its header says it follows the testing conventions; a newexamples/udp_only_public_tracker_production_style.rsstarts the server the way the binary does (notestingmodule), and both headers explain the difference.udp-serverpart of pattern A resolved. The evidence is inmanual-verification-evidence.md(V1 to V8), and there is an implementation retrospective.Verification
udp-serverbuild has no direct dependency on the registry crate (27 direct normal dependencies before, 26 after; it stays reachable throughtracker-coreandudp-core), andsrc/testing/is absent from the default rustdoc output.udp-server(233 + 16 + 1 + 2),axum-health-check-api-server(15 + 8),axum-rest-api-serverandrest-api-runtime-adapter, plain, with--all-featuresand with--all-targets --all-features; norequired-featuresis used. Without its new dev-dependency feature the health check package fails to compile.Shipped Featurescheck is green on the real tree and red (exit 1) with the feature on the root[dependencies]entry ofudp-serveror in itsdefaultchain. The shipped-profile binary has no test environment strings and the 35cli-configurationtests pass withTORRUST_TRACKER_BINARYset to a preserved copy.cargo test --examplesand the nightly--all-featurescheck, run under plaincargo 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
testingis 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.--features testingto build it, like thesrc/unit tests. The header explains the self dev-dependency.deny.tomlself-wrapper entry and stagingCargo.lockwith the manifest.