From e1638af88a57441fdcd8091e297421db3010719f Mon Sep 17 00:00:00 2001 From: danny Date: Tue, 20 Oct 2026 20:57:16 +0200 Subject: [PATCH] M3.7: robust CLI test deadlines The --wait end-to-end test hit its 20 s wall-clock deadline under parallel-build load. It now waits on the backend's bufferOpened event and on the process exit through channels, with a generous 120 s limit that a passing run never approaches. The single-instance control tests use a 60 s timeout instead of 10 s. The other CLI tests already wait on the process without a deadline. Co-Authored-By: Claude Opus 5.5 --- apps/lutra-cli/tests/cli.rs | 40 +++++++++++++++---------- crates/control/tests/single_instance.rs | 4 ++- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/lutra-cli/tests/cli.rs b/apps/lutra-cli/tests/cli.rs index 9c4132a..caa9660 100644 --- a/apps/lutra-cli/tests/cli.rs +++ b/apps/lutra-cli/tests/cli.rs @@ -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 { 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)); } diff --git a/crates/control/tests/single_instance.rs b/crates/control/tests/single_instance.rs index e53a3a4..7c1ff6c 100644 --- a/crates/control/tests/single_instance.rs +++ b/crates/control/tests/single_instance.rs @@ -15,7 +15,9 @@ use lutra_control::rendezvous::{self, Instance}; use lutra_testkit::EngineBackend; use serde_json::{Value, json}; -const TIMEOUT: Duration = Duration::from_secs(10); +/// Generous, because these tests may run beside parallel builds; passing +/// runs never wait this long. +const TIMEOUT: Duration = Duration::from_secs(60); /// Starts a token listener for `backend` and writes its rendezvous file in /// `dir`, as the desktop's claim does.