Skip to content

Commit

Permalink
- 1.26.1 fixes.
Browse files Browse the repository at this point in the history
- panic on deadlock in delay_zero test.
- don't print spammy messages to terminal
  • Loading branch information
mtak- authored and 0xpr03 committed Oct 16, 2019
1 parent 9a4437c commit 6ccf3e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/debounce/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ impl ScheduleWorker {
// events Mutex, and retry after yielding.
match self.operations_buffer.try_lock() {
Ok(op_buf) => break (events, op_buf),
Err(std::sync::TryLockError::Poisoned {..}) => return None,
Err(std::sync::TryLockError::WouldBlock) => {
Err(::std::sync::TryLockError::Poisoned {..}) => return None,
Err(::std::sync::TryLockError::WouldBlock) => {
// drop the lock before yielding to give other threads a chance to complete
// their work.
drop(events);
std::thread::yield_now();
::std::thread::yield_now();
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions tests/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ fn one_file_many_events() {
// https://github.com/passcod/notify/issues/205
#[test]
fn delay_zero() {
let _timeout_test = fail_after("delay_zero", Duration::from_secs(2));
let tdir = TempDir::new("temp_dir").expect("failed to create temporary directory");

tdir.create("file1");
Expand All @@ -1427,9 +1428,7 @@ fn delay_zero() {
.expect("failed to watch directory");

let thread = thread::spawn(move || {
for e in rx.into_iter() {
println!("{:?}", e);
}
for _ in rx.into_iter() {}
});

for _ in 0..100 {
Expand Down
26 changes: 25 additions & 1 deletion tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use tempdir::TempDir;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::sync::mpsc::{Receiver, TryRecvError};
use std::process;
use std::sync::{mpsc::{Receiver, TryRecvError}, atomic::{AtomicBool, Ordering::SeqCst}, Arc};
use std::thread;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -43,6 +44,29 @@ pub fn recv_events_with_timeout(
evs
}

pub fn fail_after(test_name: &'static str, duration: Duration) -> impl Drop {
struct SuccessOnDrop(Arc<AtomicBool>);
impl Drop for SuccessOnDrop {
fn drop(&mut self) {
self.0.store(true, SeqCst)
}
}

let finished = SuccessOnDrop(Arc::new(AtomicBool::new(false)));
// timeout the test to catch deadlocks
{
let finished = finished.0.clone();
thread::spawn(move || {
thread::sleep(duration);
if finished.load(SeqCst) == false {
println!("test `{}` timed out", test_name);
process::abort();
}
});
}
finished
}

pub fn recv_events(rx: &Receiver<RawEvent>) -> Vec<(PathBuf, Op, Option<u32>)> {
recv_events_with_timeout(rx, Duration::from_millis(TIMEOUT_MS))
}
Expand Down

0 comments on commit 6ccf3e8

Please sign in to comment.