persona drain tests: the paged read, the turn key, the refused put told, the beat room, the unchanged state, the ack (Soul's pins)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6e42673599
commit
f9357e8909
1 changed files with 15 additions and 4 deletions
|
|
@ -55,13 +55,15 @@ struct FakeMouth {
|
|||
acks: RefCell<Vec<u64>>,
|
||||
reads: Cell<usize>,
|
||||
ack_fails: Cell<bool>,
|
||||
/// How many deliveries one page of `pending` holds.
|
||||
page: Cell<usize>,
|
||||
log: Log,
|
||||
}
|
||||
|
||||
impl Chat for Rc<FakeMouth> {
|
||||
fn pending(&self, after: u64) -> Result<ChatPending> {
|
||||
self.reads.set(self.reads.get() + 1);
|
||||
Ok(ChatPending { persona: "eureka".into(), deliveries: self.held.borrow().iter().filter(|delivery| delivery.seq > after).cloned().collect(), tail: Some(vec![]), tail_gaps: vec![] })
|
||||
Ok(ChatPending { persona: "eureka".into(), deliveries: self.held.borrow().iter().filter(|delivery| delivery.seq > after).take(self.page.get()).cloned().collect(), tail: Some(vec![]), tail_gaps: vec![] })
|
||||
}
|
||||
fn send(&self, request: &ChatSendRequest) -> Result<ChatSendReceipt> {
|
||||
self.sent.borrow_mut().push(request.clone());
|
||||
|
|
@ -188,7 +190,7 @@ impl Rig {
|
|||
let dir = TempDir::new().unwrap();
|
||||
ControlWriter::open(dir.path().join("control.cc")).unwrap().set_brake(true, at(0), "op").unwrap();
|
||||
SwarmWriter::open(dir.path().join("swarm.cc")).unwrap().set_brake(true, at(0), "op").unwrap();
|
||||
let mouth = Rc::new(FakeMouth { held: RefCell::new(deliveries), sent: RefCell::default(), acks: RefCell::default(), reads: Cell::new(0), ack_fails: Cell::new(false), log: log.clone() });
|
||||
let mouth = Rc::new(FakeMouth { held: RefCell::new(deliveries), sent: RefCell::default(), acks: RefCell::default(), reads: Cell::new(0), ack_fails: Cell::new(false), page: Cell::new(usize::MAX), log: log.clone() });
|
||||
let store = Rc::new(FakeStore { stored: RefCell::new(control()), puts: RefCell::default(), outside: Cell::new(0), log: log.clone() });
|
||||
let trace = Rc::new(MemTrace { rows: RefCell::default(), fail: Cell::new(false), log: log.clone() });
|
||||
Self { mouth, store, trace, log, dir }
|
||||
|
|
@ -473,9 +475,18 @@ fn t_l2_a_turn_key_comes_from_the_mouth_and_her_trace_not_the_clock() {
|
|||
rig.run(scripted(false));
|
||||
let first: Vec<String> = rig.trace.rows.borrow().iter().map(|(key, _)| key.clone()).collect();
|
||||
assert_eq!(first, ["s9-n0-t0", "s9-n0-t1"]);
|
||||
rig.mouth.held.borrow_mut().push(line(9, &room(1), META, "again"));
|
||||
rig.mouth.held.borrow_mut().push(line(10, &room(1), META, "again"));
|
||||
rig.run(scripted(false));
|
||||
let keys: Vec<String> = rig.trace.rows.borrow().iter().map(|(key, _)| key.clone()).collect();
|
||||
assert_eq!(keys.len(), 3);
|
||||
assert_eq!(keys[2], "s9-n2-t0", "the same newest seq under a longer trace is another key");
|
||||
assert_eq!(keys[2], "s10-n2-t0", "the key follows the newest seq and the trace's length");
|
||||
}
|
||||
|
||||
/// The mouth pages what is pending; the drain reads to the end of it, as the heartbeat does, so the wake rule and the ack see one queue.
|
||||
#[test]
|
||||
fn t_l2_the_drain_reads_every_page_of_what_is_pending() {
|
||||
let rig = Rig::new((1..=5).map(|seq| line(seq, &room(seq), META, "hello")).collect());
|
||||
rig.mouth.page.set(2);
|
||||
assert_eq!(rig.run(scripted(false)), Outcome::Drained { turns: 3, acked_through: Some(3), put_refused: 0 });
|
||||
assert_eq!(rig.held_seqs(), [4, 5], "three turns from five lines on three pages: a first page alone would hold two rooms");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue