[control] Tests first: CLI token races, unsaved pause keeps the journal, lost share records never lower the epoch or shrink the deny list (red)
This commit is contained in:
@@ -558,6 +558,54 @@ mod unix {
|
||||
env.assert_consistent().await;
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn a_pause_that_cannot_be_saved_keeps_the_journal_and_a_restart_finishes_the_revert() {
|
||||
let good = Echo::start("good").await;
|
||||
let sick = Echo::start("sick").await;
|
||||
sick.health.store(500, std::sync::atomic::Ordering::SeqCst);
|
||||
let mut env = Env::new(EnvSpec { watch_secs: 3, ..Default::default() }).await;
|
||||
// A full disk, as far as paused.json is concerned.
|
||||
env.start_control_env(None, &[("IANITOR_TEST_FAIL_WRITE", "paused.json")]);
|
||||
let kept = env.add_host(host("a.test", &good.url(), true)).await;
|
||||
let good_edge = env.file("edge/edge.json");
|
||||
let good_tree = env.git(&["rev-parse", "refs/heads/main^{tree}"]);
|
||||
let r = env.call("POST", "/api/v1/hosts", Some(json!({ "host": host("b.test", &sick.url(), true) }))).await;
|
||||
let id = r.json["apply"]["id"].as_str().unwrap().to_owned();
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(10);
|
||||
while env.call("GET", &format!("/api/v1/applies/{id}"), None).await.json["commit"].is_null() {
|
||||
assert!(std::time::Instant::now() < deadline);
|
||||
tokio::time::sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
let lock = env.repo().join("refs/heads/main.lock");
|
||||
std::fs::write(&lock, "").unwrap();
|
||||
let rec = env.wait_apply(&id).await;
|
||||
assert_eq!(rec["state"], "needs_attention", "{rec}");
|
||||
// The pause is not on disk, so the journal must stay, at `reverting`.
|
||||
assert!(!env.dir.join("state/paused.json").exists());
|
||||
let j: serde_json::Value = serde_json::from_str(&env.file("state/journal.json")).expect("journal kept");
|
||||
assert_eq!(j["stage"], "reverting", "{j}");
|
||||
|
||||
// Restart while the branch is still locked: still no unverified config for edge.
|
||||
env.kill_control();
|
||||
env.start_control(None);
|
||||
assert_eq!(env.edge_status().await["config_sha256"], sha256(&good_edge));
|
||||
assert_eq!(env.file("edge/edge.json"), good_edge);
|
||||
let o = env.call("GET", "/api/v1/overview", None).await;
|
||||
assert_eq!(o.json["paused"]["code"], "control.paused", "{}", o.text);
|
||||
|
||||
// Restart once the lock is gone: recovery finishes the revert and resumes.
|
||||
env.kill_control();
|
||||
std::fs::remove_file(&lock).unwrap();
|
||||
env.start_control(None);
|
||||
let rec = env.call("GET", &format!("/api/v1/applies/{id}"), None).await;
|
||||
assert_eq!(rec.json["state"], "reverted", "{}", rec.text);
|
||||
assert_eq!(env.git(&["rev-parse", "refs/heads/main^{tree}"]), good_tree);
|
||||
let o = env.call("GET", "/api/v1/overview", None).await;
|
||||
assert!(o.json["paused"].is_null(), "{}", o.text);
|
||||
assert_eq!(o.json["undo"]["target"]["change_id"], kept["id"]);
|
||||
env.assert_consistent().await;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ undo, restore, conflicts
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
|
||||
Reference in New Issue
Block a user