use std::time::Duration;
use systemd_run::{Identity, RunSystem};
#[async_std::test]
#[ignore]
#[cfg(feature = "systemd_244")]
#[cfg(feature = "unified_cgroup")]
async fn test_root_allowed_cpus() {
const PATH: &'static str = concat!(env!("OUT_DIR"), "/test-aux/threads");
let r = RunSystem::new(PATH)
.allowed_cpus(&[0])
.identity(Identity::user_group("nobody", "nogroup"))
.start()
.await
.expect("should be able to start the test program")
.wait()
.await
.expect("should be able to get the status of the Run");
assert!(!r.is_failed(), "test program should exit normally");
assert!(
r.wall_time_usage() >= Duration::from_millis(900),
"test program should run for at least 0.9s with one CPU"
);
}
#[async_std::test]
#[ignore]
#[cfg(feature = "systemd_213")]
async fn test_root_cpu_quota() {
const PATH: &'static str = concat!(env!("OUT_DIR"), "/test-aux/threads");
let r = RunSystem::new(PATH)
.cpu_quota(std::num::NonZeroU64::new(100).unwrap())
.identity(Identity::user_group("nobody", "nogroup"))
.start()
.await
.expect("should be able to start the test program")
.wait()
.await
.expect("should be able to get the status of the Run");
assert!(!r.is_failed(), "test program should exit normally");
assert!(
r.wall_time_usage() >= Duration::from_millis(900),
"test program should run for at least 0.9s with 100% CPU quota"
);
assert!(
r.wall_time_usage() <= Duration::from_millis(1100),
"test program should run for about 1s with 100% CPU quota"
);
}