[control] Files retry: only in the apply worker under the lock, reloads edge to what it writes, drops only the journal of the apply that caused the pause; swallowed aborts and pauses logged; CLI owner check before creating the state dir
This commit is contained in:
@@ -679,15 +679,24 @@ mod unix {
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn a_request_during_a_restore_watch_never_writes_the_unverified_head() {
|
||||
async fn upstream_of(env: &Env) -> String {
|
||||
let r = client::https(env.opts.https_listen, "a.test", env.roots(), &Req::get("a.test", "/"))
|
||||
.await
|
||||
.unwrap();
|
||||
let r = client::https(
|
||||
env.opts.https_listen,
|
||||
"a.test",
|
||||
env.roots(),
|
||||
&Req::get("a.test", "/"),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let v: serde_json::Value = serde_json::from_slice(&r.body).unwrap_or_default();
|
||||
format!("{} {}", r.status, v["upstream"].as_str().unwrap_or("?"))
|
||||
}
|
||||
let one = Echo::start("one").await;
|
||||
let two = Echo::start("two").await;
|
||||
let mut env = Env::new(EnvSpec { watch_secs: 4, ..Default::default() }).await;
|
||||
let mut env = Env::new(EnvSpec {
|
||||
watch_secs: 4,
|
||||
..Default::default()
|
||||
})
|
||||
.await;
|
||||
env.start_control(None);
|
||||
let kept1 = env.add_host(host("a.test", &one.url(), true)).await;
|
||||
assert_eq!(kept1["state"], "kept");
|
||||
@@ -697,35 +706,64 @@ mod unix {
|
||||
std::fs::create_dir(&ej).unwrap();
|
||||
std::fs::write(ej.join("x"), "x").unwrap();
|
||||
let r = env
|
||||
.apply("PUT", "/api/v1/hosts/a.test", Some(json!({ "host": host("a.test", &two.url(), true) })))
|
||||
.apply(
|
||||
"PUT",
|
||||
"/api/v1/hosts/a.test",
|
||||
Some(json!({ "host": host("a.test", &two.url(), true) })),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r["state"], "kept", "{r}");
|
||||
assert_eq!(upstream_of(&env).await, "200 two");
|
||||
// Restore the first version; its upstream is sick now, so its watch will fail.
|
||||
one.health.store(500, std::sync::atomic::Ordering::SeqCst);
|
||||
let r = env.call("POST", "/api/v1/restore", Some(json!({ "change_id": kept1["id"] }))).await;
|
||||
let r = env
|
||||
.call(
|
||||
"POST",
|
||||
"/api/v1/restore",
|
||||
Some(json!({ "change_id": kept1["id"] })),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, 202, "{}", r.text);
|
||||
let id = r.json["apply"]["id"].as_str().unwrap().to_owned();
|
||||
let deadline = std::time::Instant::now() + Duration::from_secs(20);
|
||||
loop {
|
||||
let s = env.call("GET", &format!("/api/v1/applies/{id}"), None).await;
|
||||
let s = env
|
||||
.call("GET", &format!("/api/v1/applies/{id}"), None)
|
||||
.await;
|
||||
if s.json["state"] == "watching" {
|
||||
break;
|
||||
}
|
||||
assert!(std::time::Instant::now() < deadline, "never watched: {}", s.text);
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"never watched: {}",
|
||||
s.text
|
||||
);
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
}
|
||||
// The disk problem goes away; a write request arrives during the watch.
|
||||
std::fs::remove_dir_all(&ej).unwrap();
|
||||
let _ = env
|
||||
.call("POST", "/api/v1/hosts", Some(json!({ "host": host("a.test", &two.url(), true) })))
|
||||
.call(
|
||||
"POST",
|
||||
"/api/v1/hosts",
|
||||
Some(json!({ "host": host("a.test", &two.url(), true) })),
|
||||
)
|
||||
.await;
|
||||
assert!(env.dir.join("state/journal.json").exists(), "the Restore's journal is still there");
|
||||
assert!(!ej.exists() || env.file("edge/edge.json").contains(&two.url()), "edge.json not written from the head under watch");
|
||||
assert!(
|
||||
env.dir.join("state/journal.json").exists(),
|
||||
"the Restore's journal is still there"
|
||||
);
|
||||
assert!(
|
||||
!ej.exists() || env.file("edge/edge.json").contains(&two.url()),
|
||||
"edge.json not written from the head under watch"
|
||||
);
|
||||
let rec = env.wait_apply(&id).await;
|
||||
assert_ne!(rec["state"], "kept", "{rec}");
|
||||
let now = upstream_of(&env).await;
|
||||
assert_eq!(now, "200 two", "after the Restore was undone, edge serves the failed Restore's config ({now})");
|
||||
assert_eq!(
|
||||
now, "200 two",
|
||||
"after the Restore was undone, edge serves the failed Restore's config ({now})"
|
||||
);
|
||||
}
|
||||
|
||||
/// Edge gone while a revert runs: control cannot see what edge serves, so it does not
|
||||
|
||||
Reference in New Issue
Block a user