summaryrefslogtreecommitdiffstats
path: root/tests/dispatch.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 16:31:58 +0000
committeraur-build <aur-build@localhost>2026-11-18 16:31:58 +0000
commit101f077200e80c7869e4549db645ed94b01acb1b (patch)
treef8560d143ef2afe1a3d675a203c693a09cbc451b /tests/dispatch.rs
parentf8370b48f3e4464a1454d0ff7af1819b5448c619 (diff)
downloadaur-build-101f077200e80c7869e4549db645ed94b01acb1b.tar.gz
aur-build-101f077200e80c7869e4549db645ed94b01acb1b.zip
db: the build state machine is an enum, and a state write is a compare-and-swap
`build_state` was seven `&str` constants and `set_state(&str)` would write any string a caller invented, so the machine existed only as `WHERE state IN (...)` clauses scattered across six modules and nothing could say that `succeeded → running` is nonsense. It is `db::model::BuildState` now: parsed where a row is read (a state the code cannot name is an error, not an empty string — which also retires m-12's `current_state` returning `""`), and `set_state` takes the variant and writes only if the row's current state is one of `to`'s legal predecessors. A refused transition writes nothing and says why. Writing the machine down surfaced three things that were true of the flows but of nobody's documentation. The step loop re-asserts `Running` at every step boundary, so a self-write is a no-op and not a move — every state accepts its own name. A failed build is resumed *on its own row* (I5: the step checkpoints say where to continue), so `failed → running` is a real transition. And `builds::retry` — the UI's requeue button — moved any row to `queued` unconditionally, including one that had already published, re-queueing a build whose every step was checkpointed as done; it goes through the machine now and is refused with a reason. `requeue_transient` likewise. What the CAS buys is the zombie case, which no test covered: a worker's lease expires mid-step, the reaper returns the build to the queue, and the original worker — still running — comes back and writes `succeeded` over whatever the new owner has since done. That write now fails loudly and the queue keeps ownership. `builds_for_pkgbase` had a second, hand-copied row mapper that dropped unreadable rows with `filter_map(|r| r.ok())`; it shares `row_to_build` now and a bad row fails the query instead of vanishing from the package page (m-9's policy, applied where it bit). `tests/state_machine.rs` pins the whole table, the zombie refusal, the unknown state, the terminal build that does not move, and the requeue-of-a-published- build refusal. `tests/live.rs` walks a build through `running` before succeeding instead of teleporting it.
Diffstat (limited to 'tests/dispatch.rs')
-rw-r--r--tests/dispatch.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/dispatch.rs b/tests/dispatch.rs
index c70dd6b..6721fc8 100644
--- a/tests/dispatch.rs
+++ b/tests/dispatch.rs
@@ -103,7 +103,7 @@ fn an_expired_lease_is_requeued_and_its_running_step_marked_interrupted() {
// A fresh dispatcher (as after a restart) reaps it before claiming anything.
let reaped = builds::reap_expired(&env.db).unwrap();
assert_eq!(reaped, 1, "the expired lease was not requeued");
- assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, build_state::QUEUED);
+ assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Queued);
assert_eq!(
builds::step_status(&env.db, &id, "build").unwrap().as_deref(),
Some("interrupted"),
@@ -129,7 +129,7 @@ fn a_newer_approval_cancels_an_in_flight_build_at_the_step_boundary() {
// run() honours it at the step boundary rather than mid-step.
let out = pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert!(matches!(out, pipeline::Outcome::Cancelled), "run ignored the cancellation");
- assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, build_state::CANCELLED);
+ assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Cancelled);
}
#[test]
@@ -140,9 +140,9 @@ fn a_deterministic_build_failure_is_not_retried() {
let (env, _fx) = env_with_fixture("build-fails");
let id = queued_build(&env, "build-fails");
let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone());
- let state = wait_for(&env, &id, &["failed", "succeeded"]);
+ let state = wait_for(&env, &id, &[BuildState::Failed, BuildState::Succeeded]);
pool.shutdown();
- assert_eq!(state, build_state::FAILED, "a deterministic failure should not succeed");
+ assert_eq!(state, BuildState::Failed, "a deterministic failure should not succeed");
let b = builds::get(&env.db, &id).unwrap().unwrap();
assert_eq!(b.attempt, 1, "a deterministic failure must not be retried");
assert!(b.error.unwrap_or_default().contains("build"), "no step named in the error");
@@ -165,7 +165,7 @@ fn a_transient_failure_is_retried_up_to_the_cap() {
// attempt count reaching the cap with the build left failed.
let b = wait_attempt(&env, &id, 3);
pool.shutdown();
- assert_eq!(b.state, build_state::FAILED);
+ assert_eq!(b.state, BuildState::Failed);
assert_eq!(b.attempt, 3, "a transient failure should retry up to the cap");
}
@@ -177,9 +177,9 @@ fn the_pool_takes_a_queued_build_all_the_way_to_publication() {
let id = queued_build(&env, "plain-make");
let cfg = Arc::new(env.cfg.clone());
let pool = dispatch::Pool::spawn(cfg, env.db.clone());
- let state = wait_for(&env, &id, &["succeeded", "failed"]);
+ let state = wait_for(&env, &id, &[BuildState::Succeeded, BuildState::Failed]);
pool.shutdown();
- assert_eq!(state, build_state::SUCCEEDED, "the pool did not finish the build");
+ assert_eq!(state, BuildState::Succeeded, "the pool did not finish the build");
assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_some(), "nothing was published");
assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1"));
}
@@ -218,9 +218,9 @@ fn a_reaped_build_resumes_at_the_next_incomplete_step_with_no_duplicate_work() {
);
let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone());
- let state = wait_for(&env, &id, &["succeeded", "failed"]);
+ let state = wait_for(&env, &id, &[BuildState::Succeeded, BuildState::Failed]);
pool.shutdown();
- assert_eq!(state, build_state::SUCCEEDED, "the resumed build did not finish");
+ assert_eq!(state, BuildState::Succeeded, "the resumed build did not finish");
assert_eq!(
aur_build::shims::called_with(&env.cfg.shim_dir.clone().unwrap(), "makechrootpkg", ""),
@@ -255,7 +255,7 @@ fn queued_candidate(env: &Env, name: &str) -> CandidateRow {
fn wait_attempt(env: &Env, id: &str, n: i64) -> builds::BuildRow {
for _ in 0..600 {
if let Some(b) = builds::get(&env.db, id).unwrap() {
- if b.attempt >= n && b.state == build_state::FAILED {
+ if b.attempt >= n && b.state == BuildState::Failed {
return b;
}
}
@@ -265,10 +265,10 @@ fn wait_attempt(env: &Env, id: &str, n: i64) -> builds::BuildRow {
}
/// Poll until the build reaches one of `want` (or the test gives up).
-fn wait_for(env: &Env, id: &str, want: &[&str]) -> String {
+fn wait_for(env: &Env, id: &str, want: &[BuildState]) -> BuildState {
for _ in 0..600 {
if let Some(b) = builds::get(&env.db, id).unwrap() {
- if want.contains(&b.state.as_str()) {
+ if want.contains(&b.state) {
return b.state;
}
}