1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
mod common;
use std::os::unix::process::ExitStatusExt;
use std::process::Command;
use aur_build::db::{self, builds, model::*};
use aur_build::pipeline;
use aur_build::review::{candidates, diff};
use common::*;
fn approved(env: &Env, name: &str) -> aur_build::db::model::CandidateRow {
aur_build::watch::detect::check_pkgbase(&env.cfg, &env.db, name).unwrap();
let c = candidates::pending_candidates(&env.db).unwrap().remove(0);
let dd = diff::render_and_store(&env.db, &env.cfg, &c).unwrap();
let c = candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap();
aur_build::review::approve::approve(&env.db, "t", c.id, &c.identity_hash, &dd, None).unwrap();
candidates::candidate_by_id(&env.db, c.id).unwrap().unwrap()
}
fn queued(env: &Env, name: &str) -> String {
let c = approved(env, name);
pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap()
}
fn run_cli(env: &Env, args: &[&str]) -> std::process::Output {
Command::new(env!("CARGO_BIN_EXE_aur-build"))
.arg("--root")
.arg(env.root())
.args(args)
.output()
.expect("spawn aur-build")
}
#[test]
fn a_process_killed_mid_step_resumes_from_its_checkpoints_with_no_duplicate_work() {
let (mut env, _fx) = env_with_fixture("plain-make");
let id = queued(&env, "plain-make");
env.cfg.hooks.shim_kill_parent = Some("makepkg".into());
env.cfg.save().unwrap();
let out = run_cli(&env, &["run", &id]);
let status = out.status;
assert_eq!(
status.signal(),
Some(libc::SIGKILL),
"the child should have been SIGKILLed mid-step: {} {}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
let b = builds::get(&env.db, &id).unwrap().expect("build row survived the kill");
assert!(
b.state == BuildState::Leased || b.state == BuildState::Running,
"a killed build must still look claimed, not finished: {}",
b.state
);
assert_eq!(
builds::step_status(&env.db, &id, "build").unwrap(),
Some(StepState::Running),
"the step that was running should be recorded as running"
);
let chroot_status = builds::step_status(&env.db, &id, "chroot").unwrap();
assert!(
chroot_status.is_some_and(|s| s.is_done()),
"the completed step before the crash must be checkpointed: {chroot_status:?}"
);
assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none(), "nothing was published");
env.exec("UPDATE build SET lease_expires_at='2000-01-01T00:00:00Z' WHERE id=?1", ¶ms(vec![id.as_str()]));
assert_eq!(builds::reap_expired(&env.db).unwrap(), 1);
assert_eq!(
builds::step_status(&env.db, &id, "build").unwrap(),
Some(StepState::Interrupted)
);
env.cfg.hooks.shim_kill_parent = None;
env.cfg.save().unwrap();
let out = run_cli(&env, &["run", &id]);
assert!(out.status.success(), "resume failed: {}", String::from_utf8_lossy(&out.stderr));
let shim = env.cfg.hooks.shim_dir.clone().unwrap();
assert_eq!(
aur_build::shims::called_with(&shim, "mkarchroot", ""),
0,
"the provisioning model never calls devtools, before or after a crash"
);
assert_eq!(
aur_build::shims::called_with(&shim, "makepkg", ""),
2,
"exactly one rebuild: the crashed attempt and the resumed one"
);
assert_eq!(aur_build::shims::called_with(&shim, "repo-add", ""), 1, "publish must happen once");
assert_eq!(
env.query_i64("SELECT count(*) FROM release WHERE pkgbase_id=(SELECT id FROM pkgbase WHERE name='plain-make')", &[]),
Some(1),
"no duplicate release from the resume"
);
assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1"));
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Succeeded);
}
#[test]
fn a_cancelled_build_stops_at_a_step_boundary_and_publishes_nothing() {
let (env, _fx) = env_with_fixture("plain-make");
let id = queued(&env, "plain-make");
builds::request_cancel(&env.db, &id).unwrap();
let out = pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert!(matches!(out, pipeline::Outcome::Cancelled), "{out:?}");
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().state, BuildState::Cancelled);
let shim = env.cfg.hooks.shim_dir.clone().unwrap();
assert_eq!(aur_build::shims::called_with(&shim, "repo-add", ""), 0);
assert!(db::accepted_release(&env.db, "plain-make").unwrap().is_none());
assert_eq!(env.query_i64("SELECT count(*) FROM build WHERE state='failed'", &[]), Some(0));
}
#[test]
fn a_failed_build_leaves_the_index_serving_the_old_version_and_says_so() {
let (mut env, fx) = env_with_fixture("plain-make");
let c = approved(&env, "plain-make");
let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
pipeline::run(&env.cfg, &env.db, &id).unwrap();
assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1"));
fx.bump(&[("pkgver", "2.0")]);
env.set_shim_fail("makepkg");
let c2 = approved(&env, "plain-make");
let id2 = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c2).unwrap();
let out = pipeline::run(&env.cfg, &env.db, &id2).unwrap();
assert!(matches!(out, pipeline::Outcome::Failed { .. }), "{out:?}");
assert_eq!(db::index_version(&env.db, "plain-make").unwrap().as_deref(), Some("1.0-1"));
let unbuilt = db::approved_but_unbuilt(&env.db).unwrap();
assert_eq!(unbuilt.len(), 1, "the failed approval must be surfaced: {unbuilt:?}");
assert_eq!(unbuilt[0].pkgbase, "plain-make");
assert_eq!(unbuilt[0].approved, "2.0-1");
assert_eq!(unbuilt[0].serving, "1.0-1");
let web = Web::attach(env, fx);
let attention = web.get("/attention");
assert!(attention.body.contains("Approved but unbuilt"), "no Attention section: {}", &attention.body[..600.min(attention.body.len())]);
assert!(attention.body.contains("still serving 1.0-1"), "Attention does not say what is served");
let pkg = web.get("/packages/plain-make");
assert!(pkg.body.contains("build failed"), "the package page hides the failure");
assert!(pkg.body.contains("2.0-1"), "the package page does not name the version that did not land");
}
#[test]
fn a_transient_failure_retries_but_a_deterministic_one_never_does() {
let (mut env, _fx) = env_with_fixture("build-fails");
let id = queued(&env, "build-fails");
let pool = aur_build::pipeline::dispatch::Pool::spawn(std::sync::Arc::new(env.cfg.clone()), env.db.clone());
let mut state = BuildState::Queued;
for _ in 0..400 {
if let Some(b) = builds::get(&env.db, &id).unwrap() {
state = b.state;
if state == BuildState::Failed {
break;
}
}
std::thread::sleep(std::time::Duration::from_millis(25));
}
pool.shutdown();
assert_eq!(state, BuildState::Failed);
assert_eq!(builds::get(&env.db, &id).unwrap().unwrap().attempt, 1, "a deterministic failure must not retry");
assert_eq!(db::approved_but_unbuilt(&env.db).unwrap().len(), 1);
let _ = &mut env;
}
|