[edge] Resolver and control start, tests first (QC nits): a lookup thread that panics must not leave its name stuck, and a kept tree that breaks a changed [ui] config is not written to the engines at start (red)
This commit is contained in:
@@ -385,6 +385,60 @@ url = \"{}\"
|
||||
assert!(r.text().contains("\"hosts\""), "{}", r.text());
|
||||
}
|
||||
|
||||
/// QC phase 4 (nit): a tree kept under one `[ui] socket` and read at start under another
|
||||
/// is not written to the engines; the reason is logged.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_kept_socket_upstream_that_breaks_a_changed_config_is_not_written_at_start() {
|
||||
let auth = MockAuthelia::start().await;
|
||||
let site = format!(
|
||||
"secrets = [\"ui-proof\"]
|
||||
[forward_auth]
|
||||
url = \"{}\"
|
||||
",
|
||||
auth.url()
|
||||
);
|
||||
let (mut env, sock) = socket_env(site, "a.test").await;
|
||||
let host = json!({"host": {
|
||||
"hostname": "a.test", "upstreams": [format!("unix:{}", sock.display())],
|
||||
"tls": "domi", "auth": "forward-auth",
|
||||
"request_headers": [{"action": "set", "name": "X-Ianitor-Proof", "secret": "ui-proof"}]
|
||||
}});
|
||||
let rec = env.apply("POST", "/api/v1/hosts", Some(host)).await;
|
||||
assert_eq!(
|
||||
rec["state"],
|
||||
"kept",
|
||||
"{rec}
|
||||
{}",
|
||||
env.control_log()
|
||||
);
|
||||
env.kill_control();
|
||||
// A marker in place of edge.json: a start that writes the tree to the engines replaces it.
|
||||
let before = b"{\"marker\": \"left by the test\"}\n".to_vec();
|
||||
std::fs::write(env.dir.join("edge/edge.json"), &before).unwrap();
|
||||
let moved = env.dir.join("ui-moved.sock");
|
||||
let text = std::fs::read_to_string(env.config_path())
|
||||
.unwrap()
|
||||
.replace(&sock.display().to_string(), &moved.display().to_string());
|
||||
std::fs::write(env.config_path(), text).unwrap();
|
||||
env.start_control(None);
|
||||
for _ in 0..100 {
|
||||
if env.control_log().contains("breaks control's rules") {
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||
}
|
||||
assert!(
|
||||
env.control_log().contains("breaks control's rules"),
|
||||
"{}",
|
||||
env.control_log()
|
||||
);
|
||||
assert_eq!(
|
||||
std::fs::read(env.dir.join("edge/edge.json")).unwrap(),
|
||||
before,
|
||||
"the tree was not written to the engines"
|
||||
);
|
||||
}
|
||||
|
||||
/// QC: signed in at Authelia (alice) but the client also sends a proof guess: edge must
|
||||
/// replace, not append, the proof; and Remote-User must be Authelia's.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
|
||||
@@ -258,6 +258,33 @@ mod tests {
|
||||
assert_eq!(started.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
/// QC phase 4 (nit): a lookup thread that panics must not leave its name stuck on a dead
|
||||
/// lookup; the next request for it starts a new one.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn a_panicking_lookup_does_not_poison_its_name() {
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let c = calls.clone();
|
||||
let r = Resolver::new(1, move |_, port| {
|
||||
if c.fetch_add(1, Ordering::SeqCst) == 0 {
|
||||
panic!("resolver library bug");
|
||||
}
|
||||
Ok(vec![SocketAddr::from(([127, 0, 0, 1], port))])
|
||||
});
|
||||
assert!(r.resolve("flaky.test", 80, SHORT).await.is_err());
|
||||
let mut got = None;
|
||||
for _ in 0..50 {
|
||||
match r.resolve("flaky.test", 80, SHORT).await {
|
||||
Ok(a) => {
|
||||
got = Some(a);
|
||||
break;
|
||||
}
|
||||
Err(_) => tokio::time::sleep(Duration::from_millis(20)).await,
|
||||
}
|
||||
}
|
||||
assert_eq!(got.unwrap(), vec![SocketAddr::from(([127, 0, 0, 1], 80))]);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn literals_empty_answers_and_errors() {
|
||||
let r = Resolver::new(1, |host, _| match host {
|
||||
|
||||
Reference in New Issue
Block a user