extern crate alloc;
use alloc::collections::BTreeMap;
use alloc::vec::Vec;
use core::num::NonZeroUsize;
use crate::metis::tests::support::dot as d;
use crate::metis::{ArrivalRound, SealRecord, VersionVector};
use super::super::fabric::Fabric;
use super::super::replica::Replica;
use super::super::{Note, act, assert_converged, crash, fleet_of, lineage_of, resync};
use super::{ROSTER, condense_at, horizon};
fn seal_once(fabric: &mut Fabric, fleet: &mut BTreeMap<u32, Replica>) {
let stations: Vec<u32> = fleet.keys().copied().collect();
for &station in &stations {
let _ = act(fabric, fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(fleet);
let _ = act(fabric, fleet, 1, Replica::try_declare)
.expect("the settled plane declares its boundary");
fabric.drain(fleet);
}
fn admit_at(
fabric: &mut Fabric,
fleet: &mut BTreeMap<u32, Replica>,
members: &[u32],
joiners: &[u32],
) {
for &station in members {
act(fabric, fleet, station, |replica, out| {
replica.open_arrival(joiners, out)
})
.expect("an incumbent's admission opens over the newest seal");
}
fabric.drain(fleet);
for &station in members {
let round = fleet[&station]
.epochs()
.arrival()
.expect("the admitting member holds its round");
assert!(
round.complete(),
"station {station}: the round completes once every family word folds"
);
}
}
fn install_admitted_joiner(
fabric: &mut Fabric,
fleet: &mut BTreeMap<u32, Replica>,
station: u32,
depth: NonZeroUsize,
) {
fabric.admit(station);
let checkpoint = fleet[&1]
.joiner_checkpoint_for(station)
.expect("an incumbent at its seal re-stamps for the admitted station");
let lineage = lineage_of(&fleet[&1]);
let joiner = Replica::bootstrap(checkpoint, &ROSTER, depth, &lineage)
.expect("the joiner bootstraps from the very proof that admits it");
assert_eq!(
joiner.epochs(),
fleet[&1].epochs(),
"the joiner's recognizer agrees with the incumbents'"
);
assert_eq!(joiner.effective_order(), fleet[&1].effective_order());
let _ = fleet.insert(station, joiner);
resync(fabric, fleet, station);
fabric.drain(fleet);
}
#[test]
fn an_admitted_joiner_bootstraps_at_bottom_and_co_seals() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7001, &ROSTER, 8);
seal_once(&mut fabric, &mut fleet);
assert_converged(&fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
let mut replay = None;
for station in ROSTER {
let replica = fleet.get_mut(&station).expect("roster member");
let mut outbox = Vec::new();
let _ = replica.insert_visible(0, &mut outbox);
let _ = replay.get_or_insert_with(|| {
outbox
.iter()
.find(|note| matches!(note, Note::Old { .. }))
.cloned()
.expect("an insert emits old-addressed traffic")
});
fabric.post(station, outbox);
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the complete round's declarer tags");
fabric.drain(&mut fleet);
for station in ROSTER {
let replica = &fleet[&station];
assert_eq!(replica.generation(), 3, "the admitting window sealed");
let sealed = replica
.epochs()
.newest_sealed()
.expect("the widening record is retained");
let admission = sealed
.admission()
.expect("the record carries what its winner declared");
assert!(admission.admits(4));
assert_eq!(
sealed.sealed_join().get(4),
0,
"station {station}: the joiner counted nothing toward the admitting window's minima"
);
assert!(
replica.epochs().roster().any(|seat| seat == 4),
"station {station}: the roster widened at the seal"
);
assert_eq!(
replica.watermark(),
VersionVector::new(),
"station {station}: the meet ranges over the joiner's bottom slot from this seal on"
);
assert!(
replica.epochs().arrival().is_none(),
"station {station}: the seal consumed the round"
);
}
install_admitted_joiner(&mut fabric, &mut fleet, 4, depth);
let dot = act(&mut fabric, &mut fleet, 4, |replica, out| {
replica.insert_visible(0, out)
});
assert_eq!(dot, d(4, 1), "the admitted joiner mints from bottom");
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 4, Replica::try_declare)
.expect("the admitted joiner declares the next boundary");
fabric.drain(&mut fleet);
assert_converged(&fleet);
for replica in fleet.values() {
assert_eq!(
replica.generation(),
4,
"the joiner co-sealed the next window"
);
}
let replay = replay.expect("captured pre-admission traffic");
let before = fleet[&4].epochs().clone();
let mut discard = Vec::new();
fleet
.get_mut(&4)
.expect("the joiner is installed")
.handle(&replay, &mut discard);
assert_eq!(
&before,
fleet[&4].epochs(),
"a pre-admission replay reads as a duplicate and teaches nothing"
);
}
#[test]
fn retirement_evidence_widens_with_the_roster() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7002, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
seal_once(&mut fabric, &mut fleet);
install_admitted_joiner(&mut fabric, &mut fleet, 4, depth);
let _ = act(&mut fabric, &mut fleet, 2, |replica, out| {
replica.insert_visible(0, out)
});
fabric.drain(&mut fleet);
fabric.sever(&[4]);
let deleted = act(&mut fabric, &mut fleet, 1, |replica, out| {
replica.delete_visible(0, out)
});
assert!(deleted.is_some(), "the plane has an element to delete");
fabric.drain(&mut fleet);
assert_eq!(
condense_at(&mut fleet, 1),
0,
"the widened meet waits on the joiner's acknowledgement"
);
fabric.heal();
fabric.drain(&mut fleet);
assert_eq!(
condense_at(&mut fleet, 1),
1,
"the complete widened meet licenses the excision"
);
for station in [2, 3, 4] {
assert_eq!(condense_at(&mut fleet, station), 1);
}
assert_converged(&fleet);
}
#[test]
fn an_attested_fleet_admits_and_the_carry_crosses_the_widening_seal() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7003, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
assert_converged(&fleet);
fabric.sever(&[3]);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.abandon(3, out)
});
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_departure(3, out)
})
.expect("a survivor proposes the departed member's prefix");
}
fabric.drain(&mut fleet);
for station in [1, 2] {
assert!(
fleet[&station].attested(3).is_some(),
"station {station}: the departure round sealed"
);
}
admit_at(&mut fabric, &mut fleet, &[1, 2], &[4]);
for station in [1, 2] {
let round = fleet[&station].epochs().arrival().expect("a held round");
assert!(
round.family().eq([1u32, 2]),
"station {station}: the family is the surviving members, no substitution"
);
}
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ =
act(&mut fabric, &mut fleet, 1, Replica::try_declare).expect("the surviving declarer tags");
fabric.drain(&mut fleet);
let frames: Vec<Vec<u8>> = [1u32, 2]
.iter()
.map(|station| {
let replica = &fleet[station];
assert_eq!(replica.generation(), 3);
SealRecord::from_sealed(
replica
.epochs()
.newest_sealed()
.expect("the widening record is retained"),
)
.to_bytes()
})
.collect();
assert_eq!(frames[0], frames[1], "one record, byte-identical");
for station in [1, 2] {
let replica = &fleet[&station];
assert!(replica.epochs().roster().any(|seat| seat == 4));
assert_eq!(
replica.attested(3),
Some(1),
"station {station}: the attestation re-declared over the widened family, at the \
compacted prefix the new base carries for the evictee"
);
}
crash(&mut fleet, &ROSTER, depth, 1);
assert_eq!(
fleet[&1].attested_proposal(3, 4),
Some(0),
"the restored attestation claims no possession for the unbootstrapped joiner"
);
assert_eq!(
fleet[&1].attested_proposal(3, 2),
Some(1),
"the restored attestation carries a holder's base prefix"
);
resync(&mut fabric, &fleet, 1);
fabric.drain(&mut fleet);
let _ = fleet.remove(&3);
install_admitted_joiner(&mut fabric, &mut fleet, 4, depth);
let _ = act(&mut fabric, &mut fleet, 4, |replica, out| {
replica.insert_visible(0, out)
});
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 2, Replica::try_declare)
.expect("the widened fleet declares its next boundary");
fabric.drain(&mut fleet);
assert_converged(&fleet);
}
#[test]
fn a_racing_attestation_cannot_split_the_widening_record() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7004, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_departure(3, out)
})
.expect("a survivor proposes");
}
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain_selected(&mut fleet, |_, note| {
!matches!(note, Note::Depart { .. } | Note::Adoption { .. })
});
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the complete round's declarer tags");
fabric.drain_selected(&mut fleet, |_, note| {
!matches!(note, Note::Depart { .. } | Note::Adoption { .. })
});
for station in ROSTER {
assert!(
fleet[&station].adopted(),
"station {station}: the window is open and adopted"
);
}
fabric.drain_selected(&mut fleet, |dst, note| {
dst == 1 && matches!(note, Note::Depart { .. })
});
assert!(
fleet[&1].attested(3).is_some(),
"the attestation landed mid-window at station 1"
);
assert!(fleet[&2].attested(3).is_none());
fabric.drain_selected(&mut fleet, |_, note| matches!(note, Note::Adoption { .. }));
fabric.drain(&mut fleet);
let frames: Vec<Vec<u8>> = ROSTER
.iter()
.map(|station| {
let replica = &fleet[station];
assert_eq!(replica.generation(), 3);
SealRecord::from_sealed(
replica
.epochs()
.newest_sealed()
.expect("the widening record is retained"),
)
.to_bytes()
})
.collect();
assert_eq!(
frames[0], frames[1],
"the attested and unattested folds seal one record"
);
assert_eq!(frames[1], frames[2]);
assert!(
fleet[&2].attested(3).is_none(),
"station 2 sealed without ever applying the attestation"
);
for station in ROSTER {
let sealed_admission = fleet[&station]
.epochs()
.newest_sealed()
.and_then(|sealed| sealed.admission().cloned())
.expect("the admission rode the winner at every member");
assert!(sealed_admission.admits(4));
}
}
#[test]
fn a_racing_attestation_freezes_the_round_and_the_arrival_pays_one_boundary() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7005, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
act(&mut fabric, &mut fleet, 3, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("the departing member's own admission is honest");
for station in [1, 2] {
act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("an incumbent admits");
}
fabric.drain_selected(&mut fleet, |_, note| {
!matches!(note, Note::Endorse { by: 3, .. })
});
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.abandon(3, out)
});
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_departure(3, out)
})
.expect("a survivor proposes");
}
fabric.drain_selected(&mut fleet, |dst, note| {
dst != 3 && matches!(note, Note::Depart { .. })
});
for station in [1, 2] {
assert!(fleet[&station].attested(3).is_some());
}
fabric.drain_selected(&mut fleet, |_, note| matches!(note, Note::Endorse { .. }));
for station in [1, 2] {
let round = fleet[&station]
.epochs()
.arrival()
.expect("the frozen round");
assert!(
!round.complete() && round.pending().eq([3u32]),
"station {station}: the frozen slot never fills"
);
}
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain_selected(&mut fleet, |dst, _| dst != 3);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the fleet declares plain past the frozen round");
fabric.drain_selected(&mut fleet, |dst, _| dst != 3);
for station in [1, 2] {
let replica = &fleet[&station];
assert_eq!(replica.generation(), 3);
assert!(
replica
.epochs()
.newest_sealed()
.is_some_and(|sealed| sealed.admission().is_none()),
"station {station}: the plain seal carries no admission"
);
assert!(
replica.epochs().arrival().is_none(),
"station {station}: the plain seal superseded the frozen round"
);
}
fabric.sever(&[3]);
let _ = fleet.remove(&3);
admit_at(&mut fabric, &mut fleet, &[1, 2], &[4]);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 2, Replica::try_declare)
.expect("the surviving declarer tags over the new base");
fabric.drain(&mut fleet);
for station in [1, 2] {
let replica = &fleet[&station];
assert_eq!(replica.generation(), 4);
assert!(
replica
.epochs()
.newest_sealed()
.is_some_and(|sealed| sealed.admission().is_some()),
"station {station}: the re-agreed admission rode the next winner"
);
assert!(replica.epochs().roster().any(|seat| seat == 4));
}
assert_converged(&fleet);
}
#[test]
fn an_unassenting_member_stalls_the_window_until_its_operator_admits() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7006, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.abandon(3, out)
});
}
admit_at(&mut fabric, &mut fleet, &[1, 2], &[4]);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the two-member round's declarer tags");
fabric.drain(&mut fleet);
for station in ROSTER {
assert_eq!(
fleet[&station].generation(),
2,
"station {station}: the window waits on the unassenting member"
);
}
assert!(fleet[&1].adopted() && fleet[&2].adopted());
assert!(
!fleet[&3].adopted(),
"the abandoned member stalls at its own adopt door"
);
act(&mut fabric, &mut fleet, 3, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("the stalled member's operator endorses");
fabric.drain(&mut fleet);
for station in ROSTER {
let replica = &fleet[&station];
assert_eq!(replica.generation(), 3, "station {station}: sealed wide");
let sealed = replica
.epochs()
.newest_sealed()
.expect("the widening record is retained");
assert!(
sealed
.admission()
.is_some_and(|admission| admission.admits(4))
);
assert!(
sealed.sealed_join().get(3) > 0,
"station {station}: the cured member's own word is in the join, unsubstituted"
);
assert!(replica.epochs().roster().any(|seat| seat == 4));
}
assert_converged(&fleet);
}
#[test]
fn a_late_operators_open_folds_the_waiting_words_in_one_act() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7009, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
for station in [1, 2] {
act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("an early operator admits");
}
fabric.drain(&mut fleet);
assert!(
fleet[&3].parked_len() >= 2,
"the early words wait parked for this operator's own decision"
);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
act(&mut fabric, &mut fleet, 3, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("the late operator admits");
assert!(
fleet[&3]
.epochs()
.arrival()
.is_some_and(ArrivalRound::complete),
"the open folded the parked words in the same act"
);
let _ = act(&mut fabric, &mut fleet, 3, Replica::try_declare)
.expect("the late operator declares immediately");
fabric.drain(&mut fleet);
for station in ROSTER {
let replica = &fleet[&station];
assert_eq!(replica.generation(), 3);
assert!(
replica
.epochs()
.newest_sealed()
.is_some_and(|sealed| sealed.admission().is_some()),
"station {station}: the late opener's declaration carried the tag"
);
}
assert_converged(&fleet);
}
#[test]
fn a_checkpoint_never_exports_past_a_racing_attestation() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_700B, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the complete round's declarer tags");
fabric.drain(&mut fleet);
assert!(
fleet[&1].joiner_checkpoint_for(4).is_some(),
"at the widening seal the joiner's checkpoint exports"
);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_departure(4, out)
})
.expect("a survivor proposes the joiner's empty prefix");
}
fabric.drain(&mut fleet);
assert_eq!(
fleet[&1].attested(4),
Some(0),
"the joiner minted nothing, so the agreed bound is bottom"
);
assert!(
fleet[&1].joiner_checkpoint_for(4).is_none(),
"no checkpoint is ever re-stamped for an attested identity"
);
assert!(
fleet[&1].joiner_checkpoint_for(2).is_none(),
"no checkpoint exports while the live attestations outrun the journal's"
);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the narrowed fleet declares past the eviction");
fabric.drain(&mut fleet);
assert!(
fleet[&1].joiner_checkpoint_for(2).is_some(),
"the seal re-journaled the attestation and the door reopened"
);
assert!(
fleet[&1].joiner_checkpoint_for(4).is_none(),
"the evicted identity stays refused, forever"
);
assert_converged(&fleet);
}
#[test]
fn a_reopened_round_journals_its_endorsement_once() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_700A, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
act(&mut fabric, &mut fleet, 1, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("the operator admits");
let journaled = fleet[&1].journal_notes_len();
for _ in 0..3 {
act(&mut fabric, &mut fleet, 1, |replica, out| {
replica.open_arrival(&[4], out)
})
.expect("the identical retry absorbs");
}
assert_eq!(
fleet[&1].journal_notes_len(),
journaled,
"a retried open re-emits the durable word without re-journaling it"
);
}
#[test]
fn a_partition_healed_incumbent_rederives_the_widened_family() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7007, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the complete round's declarer tags");
fabric.drain_selected(&mut fleet, |dst, note| {
dst != 3 || !matches!(note, Note::Adoption { .. })
});
assert_eq!(fleet[&1].generation(), 3, "the connected members sealed");
assert_eq!(
fleet[&3].generation(),
2,
"the partitioned member holds the open window"
);
fabric.drain(&mut fleet);
assert_eq!(fleet[&3].generation(), 3, "the healed member sealed");
assert!(fleet[&3].epochs().roster().any(|seat| seat == 4));
assert_eq!(
SealRecord::from_sealed(fleet[&3].epochs().newest_sealed().expect("retained")).to_bytes(),
SealRecord::from_sealed(fleet[&1].epochs().newest_sealed().expect("retained")).to_bytes(),
"the healed member's widening record is byte-identical"
);
assert_eq!(
fleet[&3].watermark(),
VersionVector::new(),
"the healed member's meet ranges over the joiner it learned from the record"
);
assert_converged(&fleet);
}
#[test]
fn a_crashed_declarer_rederives_its_tag() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xA221_7008, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
admit_at(&mut fabric, &mut fleet, &ROSTER, &[4]);
for station in ROSTER {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare)
.expect("the complete round's declarer tags");
let spoken: Vec<_> = fleet[&1]
.epochs()
.candidates()
.filter(|declaration| declaration.dot().station() == 1)
.map(|declaration| {
(
declaration.dot(),
declaration.admission().cloned(),
declaration.admission_commitment().copied(),
)
})
.collect();
assert_eq!(spoken.len(), 1, "one tagged candidate stands");
assert!(
spoken[0].1.is_some(),
"the declaration carries the boundary"
);
crash(&mut fleet, &ROSTER, depth, 1);
let rederived: Vec<_> = fleet[&1]
.epochs()
.candidates()
.filter(|declaration| declaration.dot().station() == 1)
.map(|declaration| {
(
declaration.dot(),
declaration.admission().cloned(),
declaration.admission_commitment().copied(),
)
})
.collect();
assert_eq!(
spoken, rederived,
"the restored declarer re-derives the same tagged content for the same dot"
);
assert!(
fleet[&1]
.epochs()
.arrival()
.is_some_and(ArrivalRound::complete),
"the journaled endorsements rebuild the complete round"
);
resync(&mut fabric, &fleet, 1);
fabric.drain(&mut fleet);
for station in ROSTER {
assert_eq!(fleet[&station].generation(), 3);
assert!(
fleet[&station]
.epochs()
.newest_sealed()
.is_some_and(|sealed| sealed.admission().is_some()),
"station {station}: the admission survived the declarer's crash"
);
}
assert_converged(&fleet);
}
#[test]
fn an_evictees_survivors_cross_the_second_boundary() {
let depth = horizon(4);
let mut fleet = fleet_of(&ROSTER, depth);
let mut fabric = Fabric::new(0xDEAD_0001, &ROSTER, 0);
seal_once(&mut fabric, &mut fleet);
fabric.sever(&[3]);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.abandon(3, out)
});
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.open_departure(3, out)
})
.expect("a survivor proposes");
}
fabric.drain(&mut fleet);
assert!(fleet[&1].attested(3).is_some());
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare).expect("declares");
fabric.drain(&mut fleet);
assert_eq!(fleet[&1].generation(), 3, "first post-attestation seal");
assert_eq!(
fleet[&1].attested(3),
Some(1),
"the carry re-declared at the evictee's compacted base prefix"
);
crash(&mut fleet, &ROSTER, depth, 1);
assert_eq!(
fleet[&1].attested(3),
Some(1),
"the restored attestation speaks the restored base's own prefix"
);
resync(&mut fabric, &fleet, 1);
fabric.drain(&mut fleet);
for station in [1, 2] {
let _ = act(&mut fabric, &mut fleet, station, |replica, out| {
replica.insert_visible(0, out)
});
}
fabric.drain(&mut fleet);
let _ = act(&mut fabric, &mut fleet, 1, Replica::try_declare).expect("declares again");
fabric.drain(&mut fleet);
assert_eq!(fleet[&1].generation(), 4, "second post-attestation seal");
}