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 <noreply@anthropic.com>
This commit is contained in:
parent
51eba0b3cb
commit
e1638af88a
2 changed files with 28 additions and 16 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue