use super::*;
#[test]
fn test_165_kill_group_command_targets_group() {
let cmd = kill_group_command(4242);
let prog = cmd.get_program().to_string_lossy().to_string();
let args: Vec<String> = cmd
.get_args()
.map(|a| a.to_string_lossy().to_string())
.collect();
assert_eq!(prog, "kill");
assert_eq!(args, vec!["-9", "--", "-4242"]);
}
#[test]
fn test_165_no_kill_when_worker_already_done() {
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};
let slot: ChildPidSlot = Arc::new(Mutex::new(Some(4242)));
let done = AtomicBool::new(true);
assert!(!kill_worker_child_group(&slot, &done));
}
#[test]
fn test_165_kill_when_worker_still_running() {
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};
let slot: ChildPidSlot = Arc::new(Mutex::new(Some(2_000_000_000)));
let done = AtomicBool::new(false); assert!(kill_worker_child_group(&slot, &done));
}
#[test]
fn test_165_no_kill_when_no_pid_recorded() {
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};
let slot: ChildPidSlot = Arc::new(Mutex::new(None));
let done = AtomicBool::new(false);
assert!(!kill_worker_child_group(&slot, &done));
}
#[cfg(unix)]
#[test]
fn test_165_configure_process_group_child_still_runs() {
use std::process::{Command, Stdio};
let mut cmd = Command::new("echo");
cmd.arg("grouped")
.stdout(Stdio::piped())
.stderr(Stdio::null());
configure_process_group(&mut cmd);
let out = cmd.output().expect("spawn echo");
assert!(out.status.success());
assert_eq!(String::from_utf8_lossy(&out.stdout).trim(), "grouped");
}
#[test]
fn test_165_timeout_path_fast_command_ok() {
let m = Machine {
hostname: "local".to_string(),
addr: "127.0.0.1".to_string(),
user: "root".to_string(),
arch: "x86_64".to_string(),
ssh_key: None,
roles: vec![],
transport: None,
container: None,
pepita: None,
cost: 0,
allowed_operators: vec![],
};
let out = exec_script_timeout(&m, "echo quick", Some(30)).expect("fast command ok");
assert!(out.success());
assert_eq!(out.stdout.trim(), "quick");
}