summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/db.rs13
-rw-r--r--tests/dispatch.rs43
-rw-r--r--tests/pipeline.rs50
3 files changed, 99 insertions, 7 deletions
diff --git a/tests/db.rs b/tests/db.rs
index 75977d1..d750b5a 100644
--- a/tests/db.rs
+++ b/tests/db.rs
@@ -237,3 +237,16 @@ fn i1_query_flags_index_entries_without_approval() {
);
assert_eq!(db::unapproved_index_entries(&env.db).unwrap(), vec!["foo".to_string()]);
}
+
+#[test]
+fn a_setting_that_is_absent_is_the_default_and_one_that_is_nonsense_falls_back() {
+ // m-9: the policy is now stated — absent means default, nonsense means
+ // default *and a complaint*, because a typo in a knob that silently does
+ // nothing is worse than a knob that refuses to apply.
+ let env = Env::new();
+ assert_eq!(db::setting_i64(&env.db, "stage_b_cooldown", 86400), 86400);
+ db::set_setting(&env.db.writer, "stage_b_cooldown", "86400x").unwrap();
+ assert_eq!(db::setting_i64(&env.db, "stage_b_cooldown", 86400), 86400);
+ db::set_setting(&env.db.writer, "stage_b_cooldown", "3600").unwrap();
+ assert_eq!(db::setting_i64(&env.db, "stage_b_cooldown", 86400), 3600);
+}
diff --git a/tests/dispatch.rs b/tests/dispatch.rs
index e62b351..8c0e4ff 100644
--- a/tests/dispatch.rs
+++ b/tests/dispatch.rs
@@ -152,12 +152,15 @@ fn a_deterministic_build_failure_is_not_retried() {
#[test]
fn a_transient_failure_is_retried_up_to_the_cap() {
- // §8.4: transient failures (network, mirror 5xx) retry with a bounded
- // number of attempts. Here the toolchain itself is missing, which surfaces
- // as an IO error — the same class as a flaky mirror.
- let (mut env, _fx) = env_with_fixture("plain-make");
- let id = queued_build(&env, "plain-make");
- env.cfg.makechrootpkg_bin = "/nonexistent/makechrootpkg-for-test".into();
+ // §8.4: a failure the outside world caused is retried, up to a bound. This
+ // drives the real path: detection recorded a `SKIP` source's digest, then
+ // the bytes became unreachable and the cache was dropped, so the build's
+ // `sources` step has to fetch and gets an `Http` failure — the class a
+ // flaky mirror produces.
+ let (mut env, fx) = env_with_fixture("skip-checksum");
+ let id = queued_build(&env, "skip-checksum");
+ std::fs::remove_file(fx.data.join("payload.bin")).expect("payload exists");
+ env.exec("DELETE FROM source_cache", &[]);
env.cfg.max_transient_attempts = 3;
env.cfg.dispatch_tick_secs = 0;
let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone());
@@ -166,7 +169,33 @@ fn a_transient_failure_is_retried_up_to_the_cap() {
let b = wait_attempt(&env, &id, 3);
pool.shutdown();
assert_eq!(b.state, BuildState::Failed);
- assert_eq!(b.attempt, 3, "a transient failure should retry up to the cap");
+ assert_eq!(b.attempt, 3, "an unreachable source should retry up to the cap");
+ assert!(
+ b.error.unwrap_or_default().contains("payload"),
+ "the recorded failure should name what could not be fetched"
+ );
+}
+
+#[test]
+fn a_missing_toolchain_is_not_retried() {
+ // m-14: this used to be the transient test. A missing `makechrootpkg`
+ // surfaces as an `Io` error, and `Io` used to mean "retry" — so a
+ // misconfigured host or a full disk burned every attempt and then went
+ // quiet. It is deterministic: the tool is not going to appear.
+ let (mut env, _fx) = env_with_fixture("plain-make");
+ let id = queued_build(&env, "plain-make");
+ env.cfg.makechrootpkg_bin = "/nonexistent/makechrootpkg-for-test".into();
+ env.cfg.max_transient_attempts = 3;
+ env.cfg.dispatch_tick_secs = 0;
+ let pool = dispatch::Pool::spawn(Arc::new(env.cfg.clone()), env.db.clone());
+ let state = wait_for(&env, &id, &[BuildState::Failed]);
+ pool.shutdown();
+ assert_eq!(state, BuildState::Failed);
+ assert_eq!(
+ builds::get(&env.db, &id).unwrap().unwrap().attempt,
+ 1,
+ "a missing binary must not be retried as if the network had hiccupped"
+ );
}
#[test]
diff --git a/tests/pipeline.rs b/tests/pipeline.rs
index 0da1612..59a1b35 100644
--- a/tests/pipeline.rs
+++ b/tests/pipeline.rs
@@ -442,3 +442,53 @@ fn a_stale_accepted_pointer_refuses_to_publish() {
}
assert!(in_index(&env).is_empty());
}
+
+// ------------------------------------------------------- withdrawal and cleanup --
+
+#[test]
+fn withdrawing_a_release_twice_is_refused_the_second_time() {
+ // m-10: the second withdraw used to report success while rewriting nothing,
+ // so an operator who clicked twice got a green result and no explanation.
+ let (env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ run_for(&env, &c);
+ let rid = db::accepted_release(&env.db, "plain-make").unwrap().unwrap().id;
+ approve::withdraw(&env.db, "tester", rid, "upstream pulled the tarball").unwrap();
+ let err = approve::withdraw(&env.db, "tester", rid, "again").unwrap_err();
+ assert!(err.to_string().contains("not published"), "{err}");
+ let err = approve::withdraw(&env.db, "tester", rid + 999, "x").unwrap_err();
+ assert!(err.to_string().contains("no release"), "{err}");
+ // The first withdrawal stands: the index no longer serves it.
+ assert!(in_index(&env).is_empty(), "the withdrawn release is still in the index");
+}
+
+#[test]
+fn a_publish_that_does_not_land_leaves_no_orphan_files_in_the_served_tree() {
+ // m-16: the artifacts are copied into the served tree before the DB commit,
+ // and when the commit refused, those bytes used to stay — files no index
+ // names, sitting in the directory consumers download from.
+ let (mut env, _fx) = env_with_fixture("plain-make");
+ let c = approve_fixture(&env, "plain-make");
+ env.set_publish_fault("before-rename");
+ let id = pipeline::enqueue_for_candidate(&env.cfg, &env.db, &c).unwrap();
+ assert!(matches!(
+ pipeline::run(&env.cfg, &env.db, &id).unwrap(),
+ pipeline::Outcome::Failed { .. }
+ ));
+ let stray: Vec<String> = std::fs::read_dir(env.cfg.repo_arch_dir())
+ .expect("arch dir")
+ .filter_map(|e| e.ok())
+ .map(|e| e.file_name().to_string_lossy().to_string())
+ .filter(|n| n.ends_with(".pkg.tar.zst") || n.ends_with(".sig"))
+ .collect();
+ assert!(stray.is_empty(), "a publish that did not land left files behind: {stray:?}");
+
+ // And the retry still works: the artifacts come from the collect dir, not
+ // from the served tree, so cleaning up costs nothing but the copy.
+ env.clear_publish_fault();
+ assert!(
+ matches!(pipeline::run(&env.cfg, &env.db, &id).unwrap(), pipeline::Outcome::Succeeded { .. }),
+ "the retry after cleanup failed"
+ );
+ assert_eq!(in_index(&env), vec![("plain-make".into(), "1.0-1".into())]);
+}