Skip to content

Commit

Permalink
Add test for System::refresh_pids
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 17, 2023
1 parent fcf73c8 commit dee5ea8
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,38 @@ fn test_process_specific_refresh() {
update_specific_and_check!(exe, with_exe, , None);
update_specific_and_check!(cwd, with_cwd, , None);
}

#[test]
fn test_refresh_pids() {
if !sysinfo::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
return;
}
let mut p = if cfg!(target_os = "windows") {
std::process::Command::new("waitfor")
.arg("/t")
.arg("3")
.arg("RefreshPids")
.stdout(std::process::Stdio::null())
.spawn()
.unwrap()
} else {
std::process::Command::new("sleep")
.arg("3")
.stdout(std::process::Stdio::null())
.spawn()
.unwrap()
};

let child_pid = Pid::from_u32(p.id() as _);
std::thread::sleep(std::time::Duration::from_secs(1));
let mut s = System::new();
let self_pid = sysinfo::get_current_pid().expect("failed to get current pid");
let pids = &[child_pid, self_pid];
s.refresh_pids(pids);
let _ = p.kill();

assert_eq!(s.processes().len(), 2);
for pid in s.processes().keys() {
assert!(pids.contains(pid));
}
}

0 comments on commit dee5ea8

Please sign in to comment.