Skip to content

Commit c4f0925

Browse files
committed
Copy manual linux test from v4
1 parent ee5b0f6 commit c4f0925

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/manual_tests_linux.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![cfg(target_os = "linux")]
2+
#![cfg(feature = "manual_tests")]
3+
4+
use std::{
5+
fs::File,
6+
io::prelude::*,
7+
thread,
8+
time::{Duration, Instant},
9+
};
10+
11+
use crossbeam_channel::{unbounded, TryRecvError};
12+
use notify::*;
13+
14+
use utils::*;
15+
mod utils;
16+
17+
const TEMP_DIR: &str = "temp_dir";
18+
19+
#[test]
20+
// Test preparation:
21+
// 1. Run `sudo echo 10 > /proc/sys/fs/inotify/max_queued_events`
22+
// 2. Uncomment the lines near "test inotify_queue_overflow" in inotify watcher
23+
fn inotify_queue_overflow() {
24+
let mut max_queued_events = String::new();
25+
let mut f = File::open("/proc/sys/fs/inotify/max_queued_events")
26+
.expect("failed to open max_queued_events");
27+
f.read_to_string(&mut max_queued_events)
28+
.expect("failed to read max_queued_events");
29+
assert_eq!(max_queued_events.trim(), "10");
30+
31+
let tdir = tempfile::Builder::new()
32+
.prefix(TEMP_DIR)
33+
.tempdir()
34+
.expect("failed to create temporary directory");
35+
36+
let (tx, rx) = unbounded();
37+
let mut watcher: RecommendedWatcher =
38+
Watcher::new(tx).expect("failed to create recommended watcher");
39+
watcher
40+
.watch(&tdir.mkpath("."), RecursiveMode::Recursive)
41+
.expect("failed to watch directory");
42+
43+
for i in 0..20 {
44+
let filename = format!("file{}", i);
45+
tdir.create(&filename);
46+
tdir.remove(&filename);
47+
}
48+
49+
sleep(100);
50+
51+
let start = Instant::now();
52+
53+
let mut rescan_found = false;
54+
while !rescan_found && start.elapsed().as_secs() < 5 {
55+
match rx.try_recv() {
56+
Ok(Err(Error {
57+
// TRANSLATION: this may not be correct
58+
kind: ErrorKind::MaxFilesWatch,
59+
..
60+
})) => rescan_found = true,
61+
Ok(Err(e)) => panic!("unexpected event err: {:?}", e),
62+
Ok(Ok(_)) => (),
63+
Err(TryRecvError::Empty) => (),
64+
Err(e) => panic!("unexpected channel err: {:?}", e),
65+
}
66+
thread::sleep(Duration::from_millis(10));
67+
}
68+
69+
assert!(rescan_found);
70+
}

0 commit comments

Comments
 (0)