Skip to content

Commit ffb202e

Browse files
Add unit test for open_files API
1 parent 4776610 commit ffb202e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/process.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,22 @@ fn test_tasks() {
11031103
});
11041104
scheduler.join().expect("Scheduler panicked");
11051105
}
1106+
1107+
#[test]
1108+
fn open_files() {
1109+
if !sysinfo::IS_SUPPORTED_SYSTEM || cfg!(feature = "apple-sandbox") {
1110+
return;
1111+
}
1112+
let pid = sysinfo::get_current_pid().expect("failed to get current pid");
1113+
let _file =
1114+
std::fs::File::create(std::env::temp_dir().join("sysinfo-open-files.test")).unwrap();
1115+
let mut s = System::new();
1116+
s.refresh_processes(ProcessesToUpdate::Some(&[pid]), false);
1117+
let cur_process = s.process(pid).unwrap();
1118+
assert!(cur_process
1119+
.open_files()
1120+
.is_some_and(|open_files| open_files > 0));
1121+
assert!(cur_process
1122+
.open_files_limit()
1123+
.is_some_and(|open_files| open_files > 0));
1124+
}

0 commit comments

Comments
 (0)