Repository navigation
refactor(axum-rest-api-server): [#2449] migrate the REST API test environment to the token lifecycle - #2643
Conversation
…est environment to the token lifecycle Environment starts the server with start_with_cancellation and a fresh token per start, holds the token-aware handles and one DropGuard, and stop() cancels the token and joins the server task and the drain controller before panicking with a message naming each failing task. The public server field is removed; the health-check API contract test stops the REST API through Environment::stop(). Co-authored-by: Copilot <[email protected]>
…ronment in the task inventory Co-authored-by: Copilot <[email protected]>
…fs, and manual verification Co-authored-by: Copilot <[email protected]>
…spective, and the prose-first record Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…y the second review Co-authored-by: Copilot <[email protected]>
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at dc9d81b0af12909c8e4d4bd90d6db031fa0fb5cd. Recomputed from the bytes at this head, against the merge base 1d14569cd; git merge-tree against develop 722f2b5b2 is clean (exit 0, no conflict), and the two sides change no file in common. The PR is seven commits: seven files, +885/−80.
Against the spec. T0 to T3 are done, and T4 stays in progress, as the records say. D1 to D4 hold: stop(self) -> Environment<Stopped> keeps its form, each start() makes a fresh token, Running holds the token-aware handles, and nothing adds an outer timeout. The 58 env.stop().await call sites ignore the returned value, so they compile unchanged. No file in packages/, src/ or tests/ reads the removed server field; its one consumer, contract.rs:121, now calls service.stop(). One token and one DropGuard is what D20 and section 8 of the event-flow ADR imply for an environment with no listener stage.
The new environment.
start_with_cancellationreturns the server task and the drain controller already spawned on the given token.stop()disarms the guard and cancels before its first await, so astop()abandoned by its caller's deadline still shuts the server down. It then joins both tasks withtokio::join!and panics once with every failure, each message matching its arm.- A drop cancels through the guard and detaches the handles, so the server ends within the drain deadline.
testingis exported unconditionally, and the doc comments describe the new shape.- The 1 s poll that costs about 2 s of suite time is the helper's documented behaviour (
signals.rs:57-59), which the spec's Risks section predicted.
The tests. All eight bound every wait with the 10 s deadline and use ephemeral ports; only the drop test polls, as the spec asks. Read against the code, each mutation A to H removes a line its named tests depend on: A, B and D the cancel or the join, C the fresh token, H the guard alone, E the concurrent join, F the timeout arm, and G the panic.
The records. The task-inventory row matches the code. The review reports follow the template, with two verdicts from its set, each recorded by a commit after it. The ticks of AC1 to AC7 follow the second round's pass and the 20:50 log entry that records the request. The log stamps precede their commits, and the 11 relative links resolve. Two small inaccuracies remain (F1, F2).
Hygiene. The subjects are Conventional, with [#2449] and the right scope, and author and committer match. Six commits carry an attribution footer naming the review bot's account, which no rule in the tree forbids; dc9d81b0a has none. git diff --check is clean, the commit-id check prints nothing, and the description closes #2449 and nothing else.
The review bot. There is no review in the capture.
Findings
- F1 Nit: the retrospective points to evidence V0 to V4, but V5 holds the automatic checks.
- F2 Nit:
task-inventory.mdkeepslast-updated-utc20:19 after a later commit re-wrapped it.
Checked, no finding: the call sites and the removed field; stop(), drop and restart; the panic messages; the drain poll; the mutations against the tests; the review reports; ticks and stamps; links; the merge with develop; the scans.
Checks
On the loop's compute hub at this head, against the merge base 1d14569cd, the #2638 merge (receipt server-gates-sojka-454; develop has since moved to 722f2b5b2, the #2636 merge): pre-commit profile gate exit 0 (86 s); linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 16 errors / 4 warnings at this head and 16 / 4 at the base re-measured, the same 20 diagnostics by path and category, none in the files this PR touches. cargo test -p torrust-tracker-axum-rest-api-server: 14 lib tests (1.25 s) and 58 integration tests (1.76 s) pass at this head; the base lists 6 lib tests, measured in a separate target directory. cargo test -p torrust-tracker-axum-health-check-api-server: 3 lib and 8 integration tests pass at this head. The 8 testing::environment tests pass in each of three consecutive runs (about 1.2 s each). cargo clippy over both packages with all targets and features and -D warnings: exit 0. On the merge of this head into develop 722f2b5b2 (tree 527d58cd0), both packages' tests pass with --locked (83 tests). GitHub checks at this head at posting time: "Package Coverage (torrust-tracker-axum-rest-api-server): in_progress/pending; Package Coverage (torrust-tracker-axum-health-check-api-server): in_progress/pending; Docker E2E: completed/skipped; Layer Boundary Bans: completed/success; Documented Clippy Allows: completed/success; Unit (nightly): in_progress/pending; Workspace Packaging: completed/success; Unit (stable): in_progress/pending; Test (Docker) (release): queued/pending; Build on windows-latest (stable): completed/success; Generate Coverage Report: completed/success; Build on ubuntu-latest (stable): completed/success; Build on macos-latest (stable): completed/success; Build on ubuntu-latest (nightly): completed/success; Build on macos-latest (nightly): completed/success; Build on windows-latest (nightly): completed/success; Discover Package Coverage: completed/success; Docs Lint: completed/success". At posting, develop is 722f2b5b2.
|
ACK dc9d81b — the migrated REST API test environment's start, stop, drop and restart paths, its eight tests against the eight recorded mutations, the 58 unchanged call sites and the removed field's one consumer, and the SI-23 records were recomputed from the bytes at this head with no blocking finding |
There was a problem hiding this comment.
🔵 Needs a closer look
No blocking defects were identified, but unit and package coverage checks remain in progress, so approval should await their results and maintainer confirmation.
No open issues 🎉
What changed in this PR
Migrates the REST API test environment to the cancellation-token lifecycle for #2449, advancing the shutdown overhaul in #1488 without changing the health-check environment’s lifecycle.
Changes:
- Adds cancellation-based start, stop, and drop cleanup, with both owned tasks joined during explicit shutdown.
- Updates the health-check contract test and adds eight lifecycle regression tests.
- Records the migration, verification evidence, and implementation review.
| File | Description |
|---|---|
packages/axum-rest-api-server/src/testing/environment.rs |
Implements token-based lifecycle management and regression tests. |
packages/axum-health-check-api-server/tests/server/contract.rs |
Uses the environment’s public stop() method. |
docs/issues/open/2449-1488-si-23-migrate-rest-api-test-environment/manual-verification-evidence.md |
Records baseline, timing, mutation tests, and validation. |
docs/issues/open/2449-1488-si-23-migrate-rest-api-test-environment/ISSUE.md |
Updates implementation progress and acceptance evidence. |
docs/issues/open/2449-1488-si-23-migrate-rest-api-test-environment/implementation-retrospective.md |
Documents implementation lessons and test-design improvements. |
docs/issues/open/2449-1488-si-23-migrate-rest-api-test-environment/agent-review-reports.md |
Records review rounds and their outcomes. |
docs/features/shutdown-process/task-inventory.md |
Marks the REST API test environment as migrated. |
Review effort: Balanced
|
ACK dc9d81b |
|
Maintainer decision on the post-merge review findings: the two Nit findings F1 and F2 from the review of this PR (threads |
Co-authored-by: Copilot <[email protected]>
…ssues/closed 87daddf chore(issues): archive closed issue #2449 spec to docs/issues/closed (Jose Celano) 8bab746 docs(pr-reviews): [#2449] audit the post-merge findings of PR #2643 (Jose Celano) Pull request description: Related to #2449 Archives the spec for issue #2449 (closed on GitHub by PR #2643) from `docs/issues/open/` to `docs/issues/closed/`, and records the post-merge review audit of PR #2643. - Moves the spec folder, sets `status: done` and the new `spec-path`, ticks the last workflow checkpoint, and adds a progress-log entry. - Marks roadmap row 16 of EPIC #1488 Done and repairs the links to the old path in EPIC #1488, EPIC #2482, the #2482 REST API gating draft, SI-17 and SI-24. - Adds the audit `docs/pr-reviews/pr-2643-review/PR-REVIEW.md`. Two Nit findings from the review of PR #2643 were unprocessed when it merged. The maintainer declined them in #2643 (comment), so both are recorded as `NO_ACTION`, and both threads are replied to and resolved. - Validation: `linter all` exits 0, `validate-audit-record.py --pr-number 2643 --base torrust/develop` exits 0, and the commit-id and closing-keyword scans found nothing. Documentation only; no code changes. ACKs for top commit: josecelano: ACK 87daddf Tree-SHA512: 6aa0c9b6213cfd02d6c150025152ca304466caa9a84d3c246d3b39588d785476092456e49ba82f605b7dcc37ca948994ee1937273ba783e7c8ec30ec363be8af
Summary
Closes #2449
Migrates the REST API test
Environment(packages/axum-rest-api-server/src/testing/environment.rs) from the legacyHaltedstart and stop toApiServer::start_with_cancellationwith a fresh token per start (SI-23, roadmap row 16 of EPIC #1488). The environment owns no event listener, so it keeps one token and oneDropGuard, not the two-token shape of the HTTP and UDP environments.Changes
Environment<Running>holds the token-aware server task, the drain controller, and oneDropGuard.stop()keeps its signature, disarms the guard, cancels, joins both tasks, and panics naming each failing task (server task failed, server task failed to join, drain timed out, drain controller failed to join). Dropping a running environment withoutstop()cancels the token and releases the binding shortly after. A stopped environment can be started again. The publicserverfield is removed and a newUnstartedalias is added.service.server.stop()now callsservice.stop().docs/features/shutdown-process/task-inventory.mdrecords the migrated environment.manual-verification-evidence.md,agent-review-reports.md, andimplementation-retrospective.md.Validation
environmenttests) and 58 integration tests. The suite takes about 2.3 s against 0.35 s before, because eachstop()now joins a drain controller that polls once per second (M2 in the evidence).linter allexits 0, and the pre-push script passed before the rebase onto the currentdevelopand again in the push hook after it.Notes
The suite has no example binary, so there is no signal scenario. SI-24 (the health-check environment) is a separate follow-up and is not touched here.