From 0e4a8793122a3b39cfb7e6dcaccfe9483d32928e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 1 Mar 2024 16:38:55 +0100 Subject: [PATCH] Add test for process::run_time --- tests/process.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/process.rs b/tests/process.rs index 02324726f..f894fb8af 100644 --- a/tests/process.rs +++ b/tests/process.rs @@ -774,3 +774,23 @@ fn test_refresh_pids() { assert!(pids.contains(pid)); } } + +#[test] +fn test_process_run_time() { + if !sysinfo::IS_SUPPORTED_SYSTEM || cfg!(feature = "apple-sandbox") { + return; + } + let mut s = System::new(); + let current_pid = sysinfo::get_current_pid().expect("failed to get current pid"); + s.refresh_process(current_pid); + let run_time = s.process(current_pid).expect("no process found").run_time(); + std::thread::sleep(std::time::Duration::from_millis(1500)); + s.refresh_process(current_pid); + let new_run_time = s.process(current_pid).expect("no process found").run_time(); + assert!( + new_run_time > run_time, + "{} not superior to {}", + new_run_time, + run_time + ); +}