PM: merge M3.7 robust CLI test deadlines
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
228669036c
2 changed files with 28 additions and 16 deletions
|
|
@ -6,8 +6,9 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{Command, Output, Stdio};
|
use std::process::{Command, Output, Stdio};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Duration;
|
||||||
|
|
||||||
use lutra_control::rendezvous::{self, Instance};
|
use lutra_control::rendezvous::{self, Instance};
|
||||||
use lutra_engine::Event;
|
use lutra_engine::Event;
|
||||||
|
|
@ -40,6 +41,11 @@ fn instance(dir: &Path) -> Arc<EngineBackend> {
|
||||||
backend
|
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 {
|
fn lutra(dir: &Path, args: &[&str]) -> Command {
|
||||||
let mut command = Command::new(env!("CARGO_BIN_EXE_lutra"));
|
let mut command = Command::new(env!("CARGO_BIN_EXE_lutra"));
|
||||||
command
|
command
|
||||||
|
|
@ -126,31 +132,35 @@ fn wait_returns_after_the_tab_is_closed() {
|
||||||
let rv = tempfile::tempdir().unwrap();
|
let rv = tempfile::tempdir().unwrap();
|
||||||
let project = tempfile::tempdir().unwrap();
|
let project = tempfile::tempdir().unwrap();
|
||||||
let file = project.path().join("COMMIT_EDITMSG");
|
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 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()])
|
let mut child = lutra(rv.path(), &["--wait", file.to_str().unwrap()])
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let deadline = Instant::now() + Duration::from_secs(20);
|
|
||||||
let id = loop {
|
let id = loop {
|
||||||
if let Some(id) = buffer_ids(&backend).first() {
|
match events
|
||||||
break *id;
|
.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));
|
thread::sleep(Duration::from_millis(300));
|
||||||
assert!(child.try_wait().unwrap().is_none(), "--wait returned early");
|
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();
|
backend.execute("buffer.close", json!({"id": id})).unwrap();
|
||||||
let deadline = Instant::now() + Duration::from_secs(20);
|
let status = exited
|
||||||
let status = loop {
|
.recv_timeout(LOAD_DEADLINE)
|
||||||
if let Some(status) = child.try_wait().unwrap() {
|
.expect("--wait did not return");
|
||||||
break status;
|
|
||||||
}
|
|
||||||
assert!(Instant::now() < deadline, "--wait did not return");
|
|
||||||
thread::sleep(Duration::from_millis(50));
|
|
||||||
};
|
|
||||||
assert_eq!(status.code(), Some(0));
|
assert_eq!(status.code(), Some(0));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ use lutra_control::rendezvous::{self, Instance};
|
||||||
use lutra_testkit::EngineBackend;
|
use lutra_testkit::EngineBackend;
|
||||||
use serde_json::{Value, json};
|
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
|
/// Starts a token listener for `backend` and writes its rendezvous file in
|
||||||
/// `dir`, as the desktop's claim does.
|
/// `dir`, as the desktop's claim does.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue