Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Mar 24, 2023
1 parent e8fc7cb commit 2fb3f25
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/apple/macos/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,29 @@ impl SystemTimeInfo {
}
}
}

#[cfg(test)]
mod test {

use super::*;

/// Regression test for <https://github.com/GuillaumeGomez/sysinfo/issues/956>.
#[test]
fn test_getting_time_interval() {
if !crate::System::IS_SUPPORTED || cfg!(feature = "apple-sandbox") {
return;
}

let port = unsafe { libc::mach_host_self() };
let mut info = SystemTimeInfo::new(port).unwrap();
info.get_time_interval(port);

std::thread::sleep(crate::System::MINIMUM_CPU_UPDATE_INTERVAL.saturating_mul(2));

let val = info.get_time_interval(port);
assert!(
val > crate::System::MINIMUM_CPU_UPDATE_INTERVAL.as_secs_f64() * 1_000_000_000.0
/ info.timebase_to_ns
);
}
}

0 comments on commit 2fb3f25

Please sign in to comment.