Repository navigation
test(axum-rest-api-server): [#2637] cover the server lifecycle - #2744
josecelano merged 13 commits into
Conversation
…e health check finding Co-authored-by: Copilot <[email protected]>
… and log the post-merge findings Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…abase a cleanup owner and bound the router tests The shared api_container helper now moves a SQLite database into a temporary directory that the returned value removes on drop, also when a test panics. The v1 routes helper and the API router helper await container setup, the request and the body inside one absolute deadline. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…erge findings Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…tration cancels the caller's token Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… its findings Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…he EPIC Co-Authored-By: Claude Sonnet 5.5 <[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
1 open issue
What changed in this PR
Adds/refactors unit tests to cover the REST API server lifecycle and improves test hygiene by enforcing timeouts and cleaning up temporary SQLite databases created during tests.
Changes:
- Add/refactor
server.rslifecycle tests (bind error, registration details, health checks, andLauncherdisplay). - Introduce shared test helpers: a global I/O deadline (
within_deadline) and a tempdir-owned SQLite database container (TestApiContainer). - Update docs/coverage evidence and add
tempfileas a dev-dependency for test cleanup.
| File | Description |
|---|---|
| packages/axum-rest-api-server/src/v1/routes.rs | Wraps test helper I/O (container + request + body) in a shared deadline helper. |
| packages/axum-rest-api-server/src/test_support.rs | Adds within_deadline, TEST_DEADLINE, and TestApiContainer to avoid hangs and database file leaks. |
| packages/axum-rest-api-server/src/server.rs | Expands/refactors lifecycle tests; uses shared deadline + shared container helper. |
| packages/axum-rest-api-server/src/routes.rs | Wraps router test helper I/O in shared deadline helper. |
| packages/axum-rest-api-server/Cargo.toml | Adds tempfile dev-dependency to support test database tempdirs. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/test-refactor-plans/server-tests.md | Adds the server lifecycle test plan and results/coverage notes. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/test-refactor-plans/README.md | Adds the new server lifecycle plan to the index. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/lessons.md | Updates lessons learned with server lifecycle findings and follow-ups. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/coverage-evidence.md | Records updated pre/post coverage measurements for the slice. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/agent-review-reports.md | Adds the independent review report for slice S5. |
| docs/issues/open/2637-1347-add-tests-axum-rest-api-server/ISSUE.md | Updates slice tracking, ledger status, and progress log entries. |
| docs/issues/open/1347-overhaul-packages-testing/EPIC.md | Updates EPIC status and latest coverage metrics for #2637. |
Review effort: Lite
…n the test deadline panic Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
ACK 275c895 |
|
Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: All 277 executable lines it added are tests, benchmarks or test support with no production behaviour, and 268 of them are still present. |

Related to #2637
Slice S5 of the
torrust-tracker-axum-rest-api-serverpackage tests (subissue of EPIC #1347): the server lifecycle (server.rs), plus two test-only fixes for post-merge review findings of earlier slices. Tests and documentation only; no production code changed.Summary
server.rs(ledger row 18): five new tests (a bind error when the address is in use; the plain start registering anHTTPbinding on the served address; the productioncheck_fnhealthy against a live server, with its info text;check_fnfailing against a dead address;Launcher'sDisplayfor TLS and plain) and a refactor of the existing ones: the sharedapi_container, one absolute deadline for every awaited operation, the dead TLS branch of the legacy test removed, and the TLS test joining both tasks. Unit-only lines 403 / 458 to 579 / 624 for the file. Ten named mutations: S1-S7, S8, S8b and S9 all killed. S8 first survived and was wrongly called an equivalent mutant; the independent review caught it, and the registration-failure test now asserts that the caller's token is cancelled.server.rsare classified in the plan: logging-only, OS faults, runtime error arms owned bytorrust-tracker-axum-server, the legacyHaltedpath owned by Overhaul: Tracker Shutdown #1488, andpanic!arms of tests.api_containernow puts its SQLite database in a temporary directory owned by the returned value, so test runs leave no database file behind); F4 is fixed (one 5 s deadline over container setup, request and body inv1/routes.rsandroutes.rs, verified with a pending future).develop, and S5 re-measured after the rebase (which also brought the The REST API health check reports Ok when the health endpoint answers a failing HTTP status #2733 fix).tempfile(already used in the workspace) for the F3 fix. Plan, S5 measurement, the EPIC tables,lessons.mdand the independent review report (REVIEW PASSED; its findings fixed).Coverage (stable Rust 1.99.1,
cargo-llvm-cov 0.6.16, filtered topackages/axum-rest-api-server/src/)develop, before this slice)The totals count the in-file test modules.
developchanged the package between the baseline and the final rebase (the #2733 fix and the stats files), which also moved the integration-only denominator. Unit tests: 159 to 167 (five from this slice, the rest fromdevelop); 58 integration tests unchanged.Files
packages/axum-rest-api-server/(src/server.rs,src/test_support.rs,src/routes.rs,src/v1/routes.rs,Cargo.toml),Cargo.lock,docs/issues/open/2637-1347-add-tests-axum-rest-api-server/,docs/issues/open/1347-overhaul-packages-testing/EPIC.md.Validation
All on the rebased branch: the pre-commit script passed for every commit and
./contrib/dev-tools/git/hooks/pre-push.shpassed.cargo test -p torrust-tracker-axum-rest-api-serverpassed (167 unit and 58 integration tests),cargo +nightly fmt --all -- --check,cargo clippy -p torrust-tracker-axum-rest-api-server --all-targets,cargo machete --with-metadata,linter markdownandlinter cspellpassed. The history was rebased ontodevelopbefore the push (the branch was never pushed); no commit was squashed.🤖 Generated with Claude Code