diff options
Diffstat (limited to 'tests/state_machine.rs')
| -rw-r--r-- | tests/state_machine.rs | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/tests/state_machine.rs b/tests/state_machine.rs index 1c05fff..a8d9b35 100644 --- a/tests/state_machine.rs +++ b/tests/state_machine.rs @@ -1,9 +1,3 @@ -//! The build state machine (§6 M-8). -//! -//! Before this was an enum, `set_state(&str)` wrote any string a caller -//! invented and the machine lived only in `WHERE state IN (...)` clauses. These -//! tests are the ones that would have failed then. - mod common; use aur_build::db::{builds, model::{BuildState, CandidateState, StepState}}; @@ -38,8 +32,7 @@ fn the_machine_refuses_a_transition_it_does_not_define() { let id = build(&env, "b1"); assert_eq!(state(&env, "b1"), BuildState::Queued); - // Queued → Succeeded: a build cannot finish without running. Before the - // enum this wrote happily and produced a succeeded build that never built. + // Queued → Succeeded: a build cannot finish without running. let err = builds::set_state(&env.db, &id, BuildState::Succeeded, None).unwrap_err(); assert!(err.to_string().contains("illegal build transition"), "{err}"); assert_eq!(state(&env, "b1"), BuildState::Queued, "a refused transition writes nothing"); @@ -73,9 +66,9 @@ fn a_terminal_build_is_history_and_does_not_move() { #[test] fn a_zombie_worker_cannot_finish_a_build_it_no_longer_owns() { // The failure this pins: a worker's lease expires mid-step, the reaper hands - // the build back to the queue, and the original worker — still running — - // comes back and writes `succeeded` over whatever the new owner did. The - // compare-and-swap in `set_state` is what makes that an error. + // the build back, and the original worker comes back and writes `succeeded` + // over whatever the new owner did. The compare-and-swap in `set_state` makes + // that an error. let env = Env::new(); let id = build(&env, "b1"); builds::claim(&env.db, "worker-1", &id, 90).unwrap(); @@ -92,25 +85,23 @@ fn a_zombie_worker_cannot_finish_a_build_it_no_longer_owns() { #[test] fn a_state_the_code_does_not_know_is_an_error_not_an_empty_string() { - // A row written by an older binary, a hand-edit, or a future migration the - // code has not caught up with must stop the process, not render as a build - // in no state at all. + // A row written by an older binary, a hand-edit, or a future migration must + // stop the process, not render as a build in no state at all. let env = Env::new(); let id = build(&env, "b1"); env.exec("UPDATE build SET state='exploded' WHERE id=?1", &[common::P::S(id.clone())]); let err = builds::get(&env.db, &id).unwrap_err(); assert!(err.to_string().contains("outside the state machine"), "{err}"); // The package page lists a pkgbase's builds with no state filter: an - // unreadable row must fail the query, not vanish from the list. + // unreadable row must fail the query, not vanish. let pb = env.query_i64("SELECT id FROM pkgbase WHERE name='x'", &[]).unwrap(); assert!(aur_build::db::builds_for_pkgbase(&env.db, pb, 10).is_err()); } #[test] fn the_transition_table_is_the_machine_the_code_actually_uses() { - // Every state may be re-written with its own name — that is a no-op, not a - // move (the step loop re-asserts Running at each boundary). What matters is - // what else is reachable, and this table is the whole machine. + // Every state may be re-written with its own name — a no-op, not a move. What + // matters is what else is reachable, and this table is the whole machine. let reachable = |from: BuildState| -> Vec<&'static str> { BuildState::ALL .iter() @@ -131,16 +122,14 @@ fn the_transition_table_is_the_machine_the_code_actually_uses() { // A failed build is resumed on its own row (I5) or requeued by a human (§8.4). assert_eq!(reachable(BuildState::Failed), ["queued", "running", "failed"]); assert_eq!(reachable(BuildState::Cancelled), ["queued", "cancelled"]); - // A published build is history. Nothing revives it; a new version is a new - // build id (§8.1), not a resurrection. + // A published build is history: a new version is a new build id (§8.1). assert_eq!(reachable(BuildState::Succeeded), ["succeeded"]); } #[test] fn requeueing_a_succeeded_build_is_refused_not_silently_requeued() { - // `builds::retry` resets the failed steps and moves the row back to the - // queue. On a build that already published there is nothing to retry, and - // the old unconditional UPDATE happily requeued it anyway. + // `builds::retry` resets the failed steps and moves the row back to the queue. + // On a build that already published there is nothing to retry. let env = Env::new(); let id = build(&env, "b1"); builds::claim(&env.db, "worker-1", &id, 90).unwrap(); @@ -154,7 +143,7 @@ fn requeueing_a_succeeded_build_is_refused_not_silently_requeued() { #[test] fn a_failed_build_is_resumed_on_its_own_row() { // I5: the resume happens on the same row, because the step checkpoints say - // where to continue. The machine has to know that, or the resume is a bug. + // where to continue. let env = Env::new(); let id = build(&env, "b1"); builds::claim(&env.db, "worker-1", &id, 90).unwrap(); @@ -171,8 +160,8 @@ fn a_failed_build_is_resumed_on_its_own_row() { // ---------------------------------------------------------- the other machines -- -/// A candidate row in `state`, inserted directly: these tests are about the -/// state column, not about how a candidate is discovered. +/// A candidate row in `state`, inserted directly: these tests are about the state +/// column, not about how a candidate is discovered. fn candidate(env: &Env, state: &str) -> i64 { env.exec( "INSERT OR IGNORE INTO pkgbase (name, aur_url, created_at) VALUES ('x', 'u', '2026-01-01T00:00:00Z')", @@ -210,8 +199,7 @@ fn a_decided_review_is_never_re_decided() { assert!(err.to_string().contains("illegal candidate transition approved"), "{err}"); assert_eq!(candidate_state(&env, id), CandidateState::Approved); - // Superseding a decided review is the one move it makes (§7.1), and a - // superseded review is history. + // Superseding a decided review is the one move it makes (§7.1). resolve(&env, id, CandidateState::Superseded).unwrap(); assert_eq!(candidate_state(&env, id), CandidateState::Superseded); assert!(resolve(&env, id, CandidateState::Approved).is_err()); @@ -229,8 +217,7 @@ fn only_an_open_review_can_be_approved() { #[test] fn a_completed_step_checkpoint_is_frozen() { - // I5: a resumed build reads these rows to decide what not to redo. A - // checkpoint that can be rewritten is not a checkpoint. + // I5: a resumed build reads these rows to decide what not to redo. let env = Env::new(); let id = build(&env, "b1"); builds::begin_step(&env.db, &id, "build", 1).unwrap(); @@ -261,8 +248,8 @@ fn an_interrupted_step_resumes_and_a_blocked_step_waits() { #[test] fn an_unnamed_state_in_any_row_is_an_error() { - // Every state column is parsed through `db::state_col`, so a value the code - // does not know stops the read instead of rendering as some other state. + // Every state column is parsed through `db::state_col`, so an unknown value + // stops the read instead of rendering as some other state. let env = Env::new(); let cid = candidate(&env, "approved"); env.exec( |
