Skip to content

Commit c9c1393

Browse files
committed
test(cli): stdio serve helper waits for watcher readiness
- `spawn_serve_watch` returns after the child logs `[watcher] started`; the transport handshake can finish before native watches register, and an edit made in that window is never observed - child stderr is drained for the life of the session and echoed into test output - no readiness within 10 s kills and reaps the child and fails the test with its exit status - spawned serve processes log `codanna::watcher::unified` at info; notification assertions and their windows are unchanged
1 parent 58dd51f commit c9c1393

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎tests/cli/test_serve_stdio_dual_generation.rs‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,29 @@ struct ServeSession {
133133
}
134134

135135
fn spawn_serve_watch(workspace: &Path) -> ServeSession {
136-
spawn_serve_with_args(workspace, &["serve", "--watch"])
136+
let mut session = spawn_serve_with_args(workspace, &["serve", "--watch"]);
137+
let stderr = session.child.stderr.take().expect("child stderr");
138+
let (ready_tx, ready_rx) = std::sync::mpsc::channel();
139+
let stderr_reader = std::thread::spawn(move || {
140+
for line in BufReader::new(stderr).lines() {
141+
let line = line.expect("read serve stderr");
142+
eprintln!("{line}");
143+
if line.contains("[watcher] started") {
144+
ready_tx.send(()).expect("report watcher readiness");
145+
}
146+
}
147+
});
148+
149+
// The transport handshake can finish before native watches register.
150+
if let Err(error) = ready_rx.recv_timeout(Duration::from_secs(10)) {
151+
let kill = session.child.kill();
152+
let exit = session.child.wait();
153+
let stderr_joined = stderr_reader.join().is_ok();
154+
panic!(
155+
"watcher did not become ready: {error}; kill: {kill:?}; exit: {exit:?}; stderr reader joined: {stderr_joined}"
156+
);
157+
}
158+
session
137159
}
138160

139161
fn spawn_serve(workspace: &Path) -> ServeSession {
@@ -148,6 +170,7 @@ fn spawn_serve_with_args(workspace: &Path, args: &[&str]) -> ServeSession {
148170
.args(args)
149171
.current_dir(workspace)
150172
.env("HOME", &test_home)
173+
.env("RUST_LOG", "warn,codanna::watcher::unified=info")
151174
.stdin(Stdio::piped())
152175
.stdout(Stdio::piped())
153176
.stderr(Stdio::piped())

0 commit comments

Comments
 (0)