diff --git a/cli/tests/host/core.rs b/cli/tests/host/core.rs index 95707ad..1ba0285 100644 --- a/cli/tests/host/core.rs +++ b/cli/tests/host/core.rs @@ -208,7 +208,11 @@ async fn journal_recovers_after_sqlite_write_failure() { call(&h, "core.log", json!({})).await; let batches: Vec = std::fs::read_dir(w.0.join("logs/core/failed-batches")) .unwrap() - .map(|file| serde_json::from_slice(&std::fs::read(file.unwrap().path()).unwrap()).unwrap()) + .map(Result::unwrap) + // The writer atomically publishes .json files; its temporary files can + // still be incomplete while later process-exit entries are spooling. + .filter(|file| file.path().extension().is_some_and(|ext| ext == "json")) + .map(|file| serde_json::from_slice(&std::fs::read(file.path()).unwrap()).unwrap()) .collect(); assert!( batches @@ -1104,17 +1108,16 @@ async fn stop_closes_stdin_and_waits_for_exit() { let w = TestWorld::new(); let h = w.start().await; let hc = h.clone(); + let mut events = h.subscribe(); let pending = tokio::spawn(async move { hc.call("probe.wait_eof", json!({})).await }); + // Admission is not readiness: stop may otherwise close stdin before the + // request reaches the guest, so wait for the handler to enter its EOF loop. let pid = tokio::time::timeout(std::time::Duration::from_secs(20), async { loop { - if let Some((pid, _)) = h - .processes() - .into_iter() - .find(|(_, p)| p.method == "wait_eof") - { - break pid; + let event = events.recv().await.unwrap(); + if event["params"]["name"] == "waiting-eof" { + break event["params"]["params"]["pid"].clone(); } - tokio::task::yield_now().await; } }) .await diff --git a/cli/tests/plugins/probe/src/main.rs b/cli/tests/plugins/probe/src/main.rs index 972553c..7ba2cf9 100644 --- a/cli/tests/plugins/probe/src/main.rs +++ b/cli/tests/plugins/probe/src/main.rs @@ -83,6 +83,9 @@ fn unknown_id() { } fn wait_eof(lines: &mut Lines) { std::fs::write("/state/waiting", "yes").unwrap(); + send(json!({"jsonrpc":"2.0","method":"core.notify","params":{ + "name":"waiting-eof", "params":{"pid":std::env::var("SAUSAGE_PID").unwrap()} + }})); for _ in lines {} std::fs::write("/state/stopped", "yes").unwrap(); }