use processkit::Command;
pub(crate) fn skip_unless_enabled(scenario: &str) -> bool {
if std::env::var_os("PROCESSKIT_STRESS").is_some() {
return false;
}
eprintln!("[stress] skipping {scenario}: set PROCESSKIT_STRESS=1 to run");
true
}
pub(crate) fn quick_exit() -> Command {
if cfg!(windows) {
Command::new("cmd").args(["/c", "exit", "0"])
} else {
Command::new("true")
}
}
pub(crate) fn always_fail() -> Command {
if cfg!(windows) {
Command::new("cmd").args(["/c", "exit", "1"])
} else {
Command::new("sh").args(["-c", "exit 1"])
}
}
pub(crate) fn line_emitter(n: u32) -> Command {
if cfg!(windows) {
Command::new("powershell").args([
"-NoProfile",
"-Command",
&format!("for ($i = 1; $i -le {n}; $i++) {{ $i }}"),
])
} else {
Command::new("seq").arg(n.to_string())
}
}
pub(crate) fn long_sleeper() -> Command {
if cfg!(windows) {
Command::new("ping").args(["-n", "91", "127.0.0.1"])
} else {
Command::new("sleep").arg("90")
}
}
#[cfg(target_os = "linux")]
pub(crate) fn open_fd_count() -> usize {
std::fs::read_dir("/proc/self/fd")
.map(|dir| dir.count())
.unwrap_or(0)
}