@@ -395,19 +395,19 @@ mod tests {
thread::spawn(move || stream.run(move |events| tx.send(events.to_vec()).is_ok()));
fs::write(path.join("new-file"), "").unwrap();
- let events = rx.recv_timeout(Duration::from_secs(2)).unwrap();
+ let events = rx.recv_timeout(timeout()).unwrap();
let event = events.last().unwrap();
assert_eq!(event.path, path.join("new-file"));
assert!(event.flags.contains(StreamFlags::ITEM_CREATED));
fs::remove_file(path.join("existing-file-5")).unwrap();
- let mut events = rx.recv_timeout(Duration::from_secs(2)).unwrap();
+ let mut events = rx.recv_timeout(timeout()).unwrap();
let mut event = events.last().unwrap();
// we see this duplicate about 1/100 test runs.
if event.path == path.join("new-file")
&& event.flags.contains(StreamFlags::ITEM_CREATED)
{
- events = rx.recv_timeout(Duration::from_secs(2)).unwrap();
+ events = rx.recv_timeout(timeout()).unwrap();
event = events.last().unwrap();
}
assert_eq!(event.path, path.join("existing-file-5"));
@@ -440,13 +440,13 @@ mod tests {
});
fs::write(path.join("new-file"), "").unwrap();
- let events = rx.recv_timeout(Duration::from_secs(2)).unwrap();
+ let events = rx.recv_timeout(timeout()).unwrap();
let event = events.last().unwrap();
assert_eq!(event.path, path.join("new-file"));
assert!(event.flags.contains(StreamFlags::ITEM_CREATED));
fs::remove_file(path.join("existing-file-5")).unwrap();
- let events = rx.recv_timeout(Duration::from_secs(2)).unwrap();
+ let events = rx.recv_timeout(timeout()).unwrap();
let event = events.last().unwrap();
assert_eq!(event.path, path.join("existing-file-5"));
assert!(event.flags.contains(StreamFlags::ITEM_REMOVED));
@@ -477,11 +477,11 @@ mod tests {
});
fs::write(path.join("new-file"), "").unwrap();
- assert_eq!(rx.recv_timeout(Duration::from_secs(2)).unwrap(), "running");
+ assert_eq!(rx.recv_timeout(timeout()).unwrap(), "running");
// Dropping the handle causes `EventStream::run` to return.
drop(handle);
- assert_eq!(rx.recv_timeout(Duration::from_secs(2)).unwrap(), "stopped");
+ assert_eq!(rx.recv_timeout(timeout()).unwrap(), "stopped");
}
#[test]
@@ -500,11 +500,14 @@ mod tests {
}
fn flush_historical_events() {
- let duration = if std::env::var("CI").is_ok() {
- Duration::from_secs(2)
+ thread::sleep(timeout());
+ }
+
+ fn timeout() -> Duration {
+ if std::env::var("CI").is_ok() {
+ Duration::from_secs(4)
} else {
Duration::from_millis(500)
- };
- thread::sleep(duration);
+ }
}
}