use super::*;
use crate::cli_outbound::sys;
use crate::engine::stop;
use crate::test_support::world_under;
use std::sync::atomic::Ordering;
use std::time::{Duration, Instant};
use tempfile::tempdir;
#[test]
fn serve_returns_once_a_stop_is_asked_for() {
let root = tempdir().unwrap();
let ambient = world_under(root.path());
stop::catch();
assert!(!stop::requested(), "nothing has asked for a stop yet");
sys::on_term(libc::SIGTERM);
assert!(
stop::requested(),
"the handler raises the flag and does nothing else"
);
let started = Instant::now();
assert_eq!(
Engine::serve(&ambient, &[]),
0,
"an engine that booted and stopped exits clean (bl-1d9b)"
);
assert!(
started.elapsed() < Duration::from_secs(30),
"the drop stops and joins every thread; it must not park on any of them"
);
assert!(
crate::world::layout(&ambient).tools.join("bl").exists(),
"the face seeds the world it is about to hand to every child it spawns"
);
sys::term_disposition(false);
sys::term_flag().store(false, Ordering::SeqCst);
assert!(!stop::requested());
}
#[test]
fn a_face_that_cannot_take_the_world_exits_no_engine() {
let root = tempdir().unwrap();
let ambient = world_under(root.path());
let world = crate::world::compose(&ambient);
let _held = crate::engine::sole::take(&world.yog_state_root()).expect("the first engine");
assert_eq!(
Engine::serve(&ambient, &[]),
super::NO_ENGINE,
"a second yog on one world is not an engine"
);
sys::term_disposition(false);
}