aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/simtest/holding.rs91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 4b3277a..ebc7528 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -2032,3 +2032,94 @@ async fn a_node_no_party_lists_gets_nothing_of_a_set() {
// And a holds no entry of it.
assert_eq!(entries(&a), 2);
}
+
+/// A node away while the others moved to a checkpoint: a and b forgot what came before
+/// it, and keep it a while beside their stores; c, back, gets that of them, builds the
+/// checkpoint itself, and reads what they read, what came after it too. d, with nothing
+/// and the checkpoint pinned, begins from it by its name.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_node_of_a_set_away_across_a_move_builds_the_checkpoint_itself() {
+ use crate::federation::store::passing;
+
+ let sim = Sim::with_identity(96);
+ let parties = three();
+ let (tv, lass, makefu) = &parties;
+ let (first, root, id) = federation(&[(tv, &["a"]), (lass, &["b"]), (makefu, &["c", "d"])]);
+ let a = start_on_a_set(&sim, "a", "tv", id, a_set(&root), None, false);
+ let b = start_on_a_set(&sim, "b", "lass", id, a_set(&root), None, false);
+ let c = start_on_a_set(&sim, "c", "makefu", id, a_set(&root), None, false);
+ let all = &[&a, &b, &c];
+ sim.wait_ready(all, SOON).await;
+ sim.wait_until("each holds the three entries", SOON, move || async move {
+ all.iter().all(|node| entries(node) == 3)
+ })
+ .await;
+
+ sim.net.take_down("c");
+ let gone = tv.write(&[id], "home/tv/a", s("0"));
+ let head = tv.write(&[Id::of(&gone)], "home/tv/a", s("1"));
+ let (next, [proposal, tv_yes, lass_yes]) = checkpoint_at(&parties, &first, &[Id::of(&head)]);
+ put(&a, &[&gone, &head, &proposal, &tv_yes]).await;
+ put(&b, &[&lass_yes]).await;
+ let passed = next.hash();
+ sim.wait_until(
+ "a and b moved to the checkpoint",
+ LONG,
+ move || async move {
+ all[..2]
+ .iter()
+ .all(|node| current(node) == Some(passed) && checkpoint(node) != Some(id))
+ },
+ )
+ .await;
+ let after = tv.write(&[Id::of(&head)], "home/tv/b", s("2"));
+ put(&a, &[&after]).await;
+ let moved = checkpoint(&a).expect("a store");
+ assert_eq!(checkpoint(&b), Some(moved));
+ let gone = Id::of(&gone);
+ // The store forgot it; the set keeps it a while, for whoever is still before.
+ assert_eq!(read(&a, |store| store.get(&gone).is_some()), Some(false));
+ assert_eq!(
+ a.holding.with_set(|set| set.get(&gone).is_some()),
+ Some(true)
+ );
+
+ sim.net.bring_up("c");
+ let after = Id::of(&after);
+ sim.wait_until(
+ "c moved there, and holds what came after",
+ LONG,
+ move || async move {
+ checkpoint(all[2]) == Some(moved) && holds(all[2], &[after]) && holds(all[1], &[after])
+ },
+ )
+ .await;
+ assert_eq!(counts(&c), counts(&a));
+
+ let d = sim.start_with(
+ "d",
+ &["a"],
+ Start::FromDocument(Origin::Root),
+ move |config| {
+ config.store = Some(id);
+ config.holding = holding("makefu").carrying_if(
+ Some(held::Begun::Start(passing::Start::new(
+ id,
+ moved,
+ Duration::from_secs(600),
+ ))),
+ None,
+ Arc::new(Files::default()),
+ );
+ },
+ );
+ sim.wait_ready(&[&d], SOON).await;
+ let d = &d;
+ sim.wait_until(
+ "d began from the pinned checkpoint, and caught up",
+ LONG,
+ move || async move { checkpoint(d) == Some(moved) && holds(d, &[after]) },
+ )
+ .await;
+ assert_eq!(counts(d), counts(&a));
+}