use super::super::TTL_SECONDS;
use super::super::run::LISTEN_SECONDS;
use super::stream::{ending, piece, running};
use super::{NOW, call, quick, ran, took};
#[test]
fn a_machine_is_busy_from_the_hand_off() {
let mail = quick();
mail.post(NOW, "local", &call("laptop", "bz"));
assert!(!mail.busy(NOW, "laptop"), "nobody has taken it");
assert_eq!(took(&mail, "laptop").len(), 1);
assert!(mail.busy(NOW, "laptop"));
assert!(!mail.busy(NOW, "desktop"), "one machine's job is its own");
}
#[test]
fn busy_ends_by_the_rules_that_end_a_run() {
let mail = quick();
let id = running(&mail);
assert!(mail.busy(NOW + LISTEN_SECONDS, "laptop"));
assert!(
!mail.busy(NOW + LISTEN_SECONDS + 1, "laptop"),
"its asker has not asked in thirty seconds"
);
mail.complete(NOW, "laptop", &id, &piece("half", ""))
.expect("in flight");
let heard = NOW + LISTEN_SECONDS;
mail.collect(heard, "local", &id, None).expect("listening");
assert!(mail.busy(heard, "laptop"));
assert!(
!mail.busy(heard + 1, "laptop"),
"its machine has not posted in thirty seconds"
);
let id = running(&mail);
assert!(mail.busy(NOW, "laptop"));
mail.complete(NOW, "laptop", &id, &ending("done", 0))
.expect("in flight");
assert!(
!mail.busy(NOW, "laptop"),
"a finished job is not a running one"
);
}
#[test]
fn what_a_machine_last_said_is_known_while_it_works() {
let mail = quick();
let (read, other) = (call("laptop", "bz"), call("laptop", "shell"));
mail.remember(NOW, &read, &ran(0));
assert_eq!(mail.known(NOW, &read), None, "an idle machine is asked");
running(&mail);
assert_eq!(mail.known(NOW, &read), Some(ran(0)));
assert_eq!(mail.known(NOW, &other), None, "another read's answer");
mail.remember(NOW, &read, &ran(7));
assert_eq!(
mail.known(NOW, &read),
Some(ran(7)),
"replaced, not kept beside"
);
let late = NOW + TTL_SECONDS + 1;
mail.post(late, "local", &call("laptop", "bz"));
assert_eq!(took(&mail, "laptop").len(), 1);
assert!(mail.busy(late, "laptop"));
assert_eq!(mail.known(late, &read), None, "an hour old is not known");
}