From 1517ccf80b97bd7083b2f62b3167d4378e895f1c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 19 May 2021 16:03:30 +0200 Subject: [PATCH] Always flush historical events in `fsevent` tests --- fsevent/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fsevent/src/lib.rs b/fsevent/src/lib.rs index e6f8bcfe45..95171f835c 100644 --- a/fsevent/src/lib.rs +++ b/fsevent/src/lib.rs @@ -307,14 +307,12 @@ mod tests { for i in 0..10 { fs::write(path.join(format!("existing-file-{}", i)), "").unwrap(); } + flush_historical_events(); let (tx, rx) = mpsc::channel(); let (stream, handle) = EventStream::new(&[&path], Duration::from_millis(50)); thread::spawn(move || stream.run(move |events| tx.send(events.to_vec()).is_ok())); - // Flush any historical events. - rx.recv_timeout(Duration::from_secs(2)).ok(); - fs::write(path.join("new-file"), "").unwrap(); let events = rx.recv_timeout(Duration::from_secs(2)).unwrap(); let event = events.last().unwrap(); @@ -338,6 +336,7 @@ mod tests { for i in 0..10 { fs::write(path.join(format!("existing-file-{}", i)), "").unwrap(); } + flush_historical_events(); let (tx, rx) = mpsc::channel(); let (stream, handle) = EventStream::new(&[&path], Duration::from_millis(50)); @@ -350,7 +349,7 @@ mod tests { }); fs::write(path.join("new-file"), "").unwrap(); - let events = rx.recv_timeout(Duration::from_millis(800)).unwrap(); + let events = rx.recv_timeout(Duration::from_secs(2)).unwrap(); let event = events.last().unwrap(); assert_eq!(event.path, path.join("new-file")); assert!(event.flags.contains(StreamFlags::ITEM_CREATED)); @@ -368,6 +367,7 @@ mod tests { fn test_event_stream_shutdown_by_dropping_handle() { let dir = TempDir::new("test-event-stream").unwrap(); let path = dir.path().canonicalize().unwrap(); + flush_historical_events(); let (tx, rx) = mpsc::channel(); let (stream, handle) = EventStream::new(&[&path], Duration::from_millis(50)); @@ -401,4 +401,13 @@ mod tests { // This returns immediately because the handle was already dropped. stream.run(|_| true); } + + fn flush_historical_events() { + let duration = if std::env::var("CI").is_ok() { + Duration::from_secs(2) + } else { + Duration::from_millis(500) + }; + thread::sleep(duration); + } }