Skip to content

Commit 9b1732b

Browse files
committed
test(watcher): poll instead of fixed sleep to reduce CI flakes
FSEvents / inotify latency varies under load; a fixed 3s sleep was marginal on slow runners. Poll up to 15s with 100ms ticks instead — fast in the happy case, robust when the runner is loaded.
1 parent b24a0da commit 9b1732b

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

bindings/rust/src/daemon/watcher.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,25 @@ mod tests {
314314
write!(f, "fn updated() {{}}").unwrap();
315315
}
316316

317-
// Wait for the watcher to pick up the change.
318-
// FSEvents on macOS batches events; allow up to 3 seconds.
319-
tokio::time::sleep(Duration::from_millis(3000)).await;
320-
321-
// The db should now contain the new text.
322-
let db_guard = db.lock().await;
323-
assert_eq!(
324-
db_guard.file_text(&uri),
325-
Some("fn updated() {}"),
326-
"watcher should have updated db with new file content"
327-
);
317+
// Poll for the watcher to pick up the change.
318+
// FSEvents on macOS batches events and latency varies widely
319+
// under load — poll up to 15s rather than a fixed sleep to
320+
// avoid flaking CI on slow runners.
321+
let deadline = std::time::Instant::now() + Duration::from_secs(15);
322+
loop {
323+
if db.lock().await.file_text(&uri).map(str::to_owned)
324+
== Some("fn updated() {}".to_owned())
325+
{
326+
break;
327+
}
328+
if std::time::Instant::now() >= deadline {
329+
let last = db.lock().await.file_text(&uri).map(str::to_owned);
330+
panic!(
331+
"watcher should have updated db with new file content within 15s; \
332+
last observed text was {last:?}"
333+
);
334+
}
335+
tokio::time::sleep(Duration::from_millis(100)).await;
336+
}
328337
}
329338
}

0 commit comments

Comments
 (0)