Skip to content

Commit f7e3b9f

Browse files
committed
event-sources: fix flaky file watcher test on macOS
FSEvents will send recent historical events when the watcher is restarted. This happens when a new file is watched.
1 parent 7701402 commit f7e3b9f

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • devenv-event-sources/src

devenv-event-sources/src/fs.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,18 @@ mod tests {
508508
.write_all(b"runtime modified")
509509
.expect("write");
510510

511-
let event = tokio::time::timeout(WATCH_TIMEOUT, watcher.recv())
512-
.await
513-
.expect("timeout")
514-
.expect("event");
515-
516-
assert_eq!(event.path, runtime_file);
511+
// On macOS, notify's FSEvents backend restarts the entire stream
512+
// when a new path is added, which replays historical events for
513+
// already-watched paths. Drain until we see the runtime file.
514+
let deadline = tokio::time::Instant::now() + WATCH_TIMEOUT;
515+
loop {
516+
let remaining = deadline - tokio::time::Instant::now();
517+
match tokio::time::timeout(remaining, watcher.recv()).await {
518+
Ok(Some(e)) if e.path == runtime_file => break,
519+
Ok(Some(_)) => continue,
520+
Ok(None) => panic!("watcher channel closed before runtime file event"),
521+
Err(_) => panic!("timeout waiting for runtime file change event"),
522+
}
523+
}
517524
}
518525
}

0 commit comments

Comments
 (0)