Skip to content

Commit

Permalink
Merge pull request #962 from GuillaumeGomez/strenghten-test
Browse files Browse the repository at this point in the history
Strenghten test `test_wait_non_child`
  • Loading branch information
GuillaumeGomez committed Mar 24, 2023
2 parents 209aaed + 004907a commit 9e7dbd7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/process.rs
Expand Up @@ -531,6 +531,8 @@ fn test_wait_non_child() {
return;
}

let before = std::time::Instant::now();

// spawn non child process.
let p = if !cfg!(target_os = "linux") {
return;
Expand All @@ -545,8 +547,6 @@ fn test_wait_non_child() {
};
let pid = Pid::from_u32(p.id());

let before = std::time::Instant::now();

let mut s = sysinfo::System::new();
s.refresh_process(pid);
let process = s.process(pid).expect("Process not found!");
Expand All @@ -558,8 +558,16 @@ fn test_wait_non_child() {
assert!(!s.refresh_process(pid));

// should wait for 2s.
assert!(before.elapsed() > std::time::Duration::from_millis(2000));
assert!(before.elapsed() < std::time::Duration::from_millis(3000));
assert!(
before.elapsed() > std::time::Duration::from_millis(1900),
"Elapsed time {:?} is not greater than 1900ms",
before.elapsed()
);
assert!(
before.elapsed() < std::time::Duration::from_millis(3000),
"Elapsed time {:?} is not less than 3000ms",
before.elapsed()
);
}

#[test]
Expand Down

0 comments on commit 9e7dbd7

Please sign in to comment.