use super::{LOCK, take};
use tempfile::tempdir;
#[test]
fn a_second_engine_on_one_world_is_refused() {
let dir = tempdir().expect("tmp");
let state = dir.path().join("state").join("yog");
let first = take(&state).expect("the first engine takes the world");
let refusal = take(&state).err().expect("the second is refused");
assert!(refusal.contains("one world has one engine"), "{refusal}");
assert!(
refusal.contains(LOCK),
"the refusal names the file: {refusal}"
);
drop(first);
take(&state).expect("the world is free once its engine has gone");
}
#[test]
fn two_worlds_are_two_exclusions() {
let dir = tempdir().expect("tmp");
let one = take(&dir.path().join("a")).expect("world a");
let two = take(&dir.path().join("b")).expect("world b");
drop((one, two));
}
#[test]
fn a_state_root_that_cannot_be_made_refuses() {
let dir = tempdir().expect("tmp");
let blocked = dir.path().join("blocked");
std::fs::write(&blocked, b"a file where the state root goes").expect("block it");
let refusal = take(&blocked).err().expect("refused");
assert!(refusal.contains("engine lock"), "{refusal}");
}