aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/simtest/holding.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index e760c8a..955b2c0 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -586,3 +586,62 @@ async fn store_attack_19() {
)
.await;
}
+
+/// A writer forked: x1 and x2, tv's, start apart from one document under one writer,
+/// and each puts an event: changes of one writer at one number. Together, the documents
+/// part, each refusing the other's changes; the events reach every node, put again from
+/// the changes refused, and every node reads the same.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn store_attack_10() {
+ let sim = Sim::with_identity(88);
+ let (tv, lass, _) = three();
+ let (_, root, id) = federation(&[(&tv, &["a", "x1", "x2"]), (&lass, &["b"])]);
+ let mut nodes = started(
+ &sim,
+ &root,
+ vec![("a", holding("tv")), ("b", holding("lass"))],
+ )
+ .await;
+ let one = events::started(Federation::NAME, &root).expect("a root");
+ for name in ["x1", "x2"] {
+ sim.net.take_down(name);
+ let doc = one.clone();
+ nodes.push(sim.start_with(
+ name,
+ &["a"],
+ Start::FromDocument(Origin::Root),
+ move |config| {
+ of_the_store(config, id, None, holding("tv"));
+ config.initial_doc = doc;
+ },
+ ));
+ }
+ let twins = [&nodes[2], &nodes[3]];
+ sim.wait_ready(&twins, SOON).await;
+ sim.wait_until("x1 and x2 hold the store", SOON, move || async move {
+ twins.iter().all(|node| node.holding.tells_members())
+ })
+ .await;
+ let given = [
+ tv.write(&[id], "home/tv/x1", s("1")),
+ tv.write(&[id], "home/tv/x2", s("2")),
+ ];
+ put(twins[0], &[&given[0]]).await;
+ put(twins[1], &[&given[1]]).await;
+ for name in ["x1", "x2"] {
+ sim.net.bring_up(name);
+ }
+ let (all, ids) = (&nodes, given.each_ref().map(|event| Id::of(event)));
+ sim.wait_until(
+ "every node holds both events, and reads the same",
+ Duration::from_secs(60),
+ move || async move {
+ let first = counts(&all[0]);
+ all.iter()
+ .all(|node| holds(node, &ids) && counts(node) == first)
+ },
+ )
+ .await;
+ // Each refuses the other's changes for good: their documents part.
+ assert_ne!(super::heads(twins[0]).await, super::heads(twins[1]).await);
+}