Skip to content

Commit 6ccf3e8

Browse files
mtak-0xpr03
authored andcommitted
- 1.26.1 fixes.
- panic on deadlock in delay_zero test. - don't print spammy messages to terminal
1 parent 9a4437c commit 6ccf3e8

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/debounce/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ impl ScheduleWorker {
3939
// events Mutex, and retry after yielding.
4040
match self.operations_buffer.try_lock() {
4141
Ok(op_buf) => break (events, op_buf),
42-
Err(std::sync::TryLockError::Poisoned {..}) => return None,
43-
Err(std::sync::TryLockError::WouldBlock) => {
42+
Err(::std::sync::TryLockError::Poisoned {..}) => return None,
43+
Err(::std::sync::TryLockError::WouldBlock) => {
4444
// drop the lock before yielding to give other threads a chance to complete
4545
// their work.
4646
drop(events);
47-
std::thread::yield_now();
47+
::std::thread::yield_now();
4848
}
4949
}
5050
};

tests/debounce.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ fn one_file_many_events() {
14151415
// https://github.com/passcod/notify/issues/205
14161416
#[test]
14171417
fn delay_zero() {
1418+
let _timeout_test = fail_after("delay_zero", Duration::from_secs(2));
14181419
let tdir = TempDir::new("temp_dir").expect("failed to create temporary directory");
14191420

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

14291430
let thread = thread::spawn(move || {
1430-
for e in rx.into_iter() {
1431-
println!("{:?}", e);
1432-
}
1431+
for _ in rx.into_iter() {}
14331432
});
14341433

14351434
for _ in 0..100 {

tests/utils/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use tempdir::TempDir;
44
use std::fs;
55
use std::io::Write;
66
use std::path::PathBuf;
7-
use std::sync::mpsc::{Receiver, TryRecvError};
7+
use std::process;
8+
use std::sync::{mpsc::{Receiver, TryRecvError}, atomic::{AtomicBool, Ordering::SeqCst}, Arc};
89
use std::thread;
910
use std::time::{Duration, Instant};
1011

@@ -43,6 +44,29 @@ pub fn recv_events_with_timeout(
4344
evs
4445
}
4546

47+
pub fn fail_after(test_name: &'static str, duration: Duration) -> impl Drop {
48+
struct SuccessOnDrop(Arc<AtomicBool>);
49+
impl Drop for SuccessOnDrop {
50+
fn drop(&mut self) {
51+
self.0.store(true, SeqCst)
52+
}
53+
}
54+
55+
let finished = SuccessOnDrop(Arc::new(AtomicBool::new(false)));
56+
// timeout the test to catch deadlocks
57+
{
58+
let finished = finished.0.clone();
59+
thread::spawn(move || {
60+
thread::sleep(duration);
61+
if finished.load(SeqCst) == false {
62+
println!("test `{}` timed out", test_name);
63+
process::abort();
64+
}
65+
});
66+
}
67+
finished
68+
}
69+
4670
pub fn recv_events(rx: &Receiver<RawEvent>) -> Vec<(PathBuf, Op, Option<u32>)> {
4771
recv_events_with_timeout(rx, Duration::from_millis(TIMEOUT_MS))
4872
}

0 commit comments

Comments
 (0)