headless: register signal handlers synchronously, split tests, drop deployment examples and wording
This commit was merged in pull request #2.
This commit is contained in:
+21
-8
@@ -40,12 +40,11 @@ fn bare_command_without_a_world_starts_init() {
|
||||
assert!(!dir.join("world").exists());
|
||||
}
|
||||
|
||||
/// `--headless` never reads stdin: with stdin at EOF the world stays up, and
|
||||
/// SIGTERM stops it cleanly (exit code 0).
|
||||
#[test]
|
||||
fn headless_ignores_stdin_eof_and_stops_cleanly_on_sigterm() {
|
||||
/// Start a headless host on a fresh world with stdin at EOF; returns once it
|
||||
/// printed its ready line (printed after the signal handlers are installed).
|
||||
fn start_headless(label: &str) -> (std::process::Child, std::io::Lines<std::io::BufReader<std::process::ChildStdout>>) {
|
||||
use std::io::{BufRead, BufReader};
|
||||
let dir = empty_dir("headless");
|
||||
let dir = empty_dir(label);
|
||||
let world = dir.join("world");
|
||||
sausage::World::create(&world).unwrap();
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_sausage"))
|
||||
@@ -57,12 +56,26 @@ fn headless_ignores_stdin_eof_and_stops_cleanly_on_sigterm() {
|
||||
.spawn()
|
||||
.unwrap();
|
||||
let mut lines = BufReader::new(child.stdout.take().unwrap()).lines();
|
||||
// The host prints this once it runs and the signal handlers are installed.
|
||||
let line = lines.next().expect("host exited before it started").unwrap();
|
||||
assert!(line.contains("headless"), "unexpected first line: {line}");
|
||||
// The host reaches EOF on stdin immediately; it must still be running.
|
||||
(child, lines)
|
||||
}
|
||||
|
||||
/// With stdin at EOF (as soon as the host starts), a headless host stays up.
|
||||
#[test]
|
||||
fn headless_ignores_stdin_eof() {
|
||||
let (mut child, _lines) = start_headless("headless-eof");
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
assert!(child.try_wait().unwrap().is_none(), "headless host exited on stdin EOF");
|
||||
let alive = child.try_wait().unwrap().is_none();
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
assert!(alive, "headless host exited on stdin EOF");
|
||||
}
|
||||
|
||||
/// SIGTERM right after the ready line stops the actors and exits with 0.
|
||||
#[test]
|
||||
fn headless_stops_cleanly_on_sigterm_right_after_ready() {
|
||||
let (mut child, lines) = start_headless("headless-term");
|
||||
let pid = child.id().to_string();
|
||||
assert!(Command::new("kill").args(["-TERM", &pid]).status().unwrap().success());
|
||||
let rest: Vec<String> = lines.map(|l| l.unwrap()).collect();
|
||||
|
||||
Reference in New Issue
Block a user