PM: merge M3.7 robust CLI test deadlines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-20 20:57:42 +02:00
commit 228669036c
2 changed files with 28 additions and 16 deletions

View file

@ -6,8 +6,9 @@
use std::path::Path;
use std::process::{Command, Output, Stdio};
use std::sync::Arc;
use std::sync::mpsc;
use std::thread;
use std::time::{Duration, Instant};
use std::time::Duration;
use lutra_control::rendezvous::{self, Instance};
use lutra_engine::Event;
@ -40,6 +41,11 @@ fn instance(dir: &Path) -> Arc<EngineBackend> {
backend
}
/// How long the tests wait for the `lutra` process. Generous, because a
/// cold process start under parallel builds can take tens of seconds; a
/// passing run returns as soon as the awaited event arrives.
const LOAD_DEADLINE: Duration = Duration::from_secs(120);
fn lutra(dir: &Path, args: &[&str]) -> Command {
let mut command = Command::new(env!("CARGO_BIN_EXE_lutra"));
command
@ -126,31 +132,35 @@ fn wait_returns_after_the_tab_is_closed() {
let rv = tempfile::tempdir().unwrap();
let project = tempfile::tempdir().unwrap();
let file = project.path().join("COMMIT_EDITMSG");
std::fs::write(&file, "msg\n").unwrap();
std::fs::write(
&file, "msg
",
)
.unwrap();
let backend = instance(rv.path());
let (sink, events) = mpsc::sync_channel(64);
backend.subscribe(sink);
let mut child = lutra(rv.path(), &["--wait", file.to_str().unwrap()])
.spawn()
.unwrap();
let deadline = Instant::now() + Duration::from_secs(20);
let id = loop {
if let Some(id) = buffer_ids(&backend).first() {
break *id;
match events
.recv_timeout(LOAD_DEADLINE)
.expect("the file was never opened")
{
Event::BufferOpened { id, .. } => break id,
_ => continue,
}
assert!(Instant::now() < deadline, "the file was never opened");
thread::sleep(Duration::from_millis(50));
};
thread::sleep(Duration::from_millis(300));
assert!(child.try_wait().unwrap().is_none(), "--wait returned early");
let (done, exited) = mpsc::channel();
thread::spawn(move || done.send(child.wait().unwrap()).unwrap());
backend.execute("buffer.close", json!({"id": id})).unwrap();
let deadline = Instant::now() + Duration::from_secs(20);
let status = loop {
if let Some(status) = child.try_wait().unwrap() {
break status;
}
assert!(Instant::now() < deadline, "--wait did not return");
thread::sleep(Duration::from_millis(50));
};
let status = exited
.recv_timeout(LOAD_DEADLINE)
.expect("--wait did not return");
assert_eq!(status.code(), Some(0));
}