use super::super::read::HAND_OFFS;
use super::{call, quick, ran, took};
#[test]
fn work_handed_to_a_read_that_never_answered_is_offered_again() {
let mail = quick();
let id = mail.post(10, "local", &call("laptop", "Bash"));
assert_eq!(took(&mail, "laptop").len(), 1, "handed over once");
assert_eq!(
took(&mail, "laptop").first().map(|i| i.id.clone()),
Some(id),
"the next read is the acknowledgement the first one never gave"
);
}
#[test]
fn an_answered_invocation_is_not_offered_again() {
let mail = quick();
let id = mail.post(10, "local", &call("laptop", "Bash"));
assert_eq!(took(&mail, "laptop").len(), 1);
assert_eq!(mail.complete("laptop", &id, &ran(0)), Ok(ran(0)));
assert!(
took(&mail, "laptop").is_empty(),
"answered work is finished work"
);
}
#[test]
fn a_read_acknowledges_only_its_own_clients_work() {
let mail = quick();
let theirs = mail.post(10, "local", &call("phone", "Bash"));
assert_eq!(took(&mail, "phone").len(), 1);
assert!(took(&mail, "laptop").is_empty());
assert_eq!(
took(&mail, "phone").first().map(|i| i.id.clone()),
Some(theirs)
);
}
#[test]
fn a_third_unanswered_hand_off_is_answered_in_doubt_naming_the_count() {
let mail = quick();
let id = mail.post(10, "local", &call("laptop", "Bash"));
for _ in 0..HAND_OFFS {
assert_eq!(
took(&mail, "laptop").first().map(|i| i.id.clone()),
Some(id.clone()),
"every read up to the bound is handed it again"
);
}
assert!(
took(&mail, "laptop").is_empty(),
"the fourth read is answered by the engine instead"
);
let said = mail
.collect("local", &id)
.expect("the asker's own handle")
.expect("the engine wrote the capture itself");
assert_eq!(said.stdout, String::new(), "nothing ran here");
assert_ne!(said.exit_code, 0, "a failed tool result, and read as one");
assert!(said.stderr.contains("\"laptop\""), "{}", said.stderr);
assert!(said.stderr.contains("3 times"), "{}", said.stderr);
assert!(
said.stderr.contains("each hand-off may have run it"),
"{}",
said.stderr
);
assert!(
said.stderr.contains("read the world before acting again"),
"{}",
said.stderr
);
}
#[test]
fn an_in_doubt_slot_is_not_offered_again() {
let mail = quick();
mail.post(10, "local", &call("laptop", "Bash"));
for _ in 0..=HAND_OFFS {
took(&mail, "laptop");
}
assert!(
took(&mail, "laptop").is_empty(),
"an answered slot is finished work, whoever answered it"
);
}
#[test]
fn a_late_completion_overwrites_an_uncollected_in_doubt_answer() {
let mail = quick();
let id = mail.post(10, "local", &call("laptop", "Bash"));
for _ in 0..=HAND_OFFS {
took(&mail, "laptop");
}
assert_eq!(mail.complete("laptop", &id, &ran(0)), Ok(ran(0)));
assert_eq!(
mail.collect("local", &id),
Ok(Some(ran(0))),
"the driver collects what the box actually captured"
);
assert!(
mail.complete("laptop", &id, &ran(0)).is_err(),
"after the collect the handle is spent"
);
}