aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/sync.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/document/sync.rs')
-rw-r--r--src/document/sync.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/document/sync.rs b/src/document/sync.rs
index 4c633f5..51cf9eb 100644
--- a/src/document/sync.rs
+++ b/src/document/sync.rs
@@ -311,6 +311,8 @@ impl SyncSession {
message.need.push(*hash);
}
}
+ // Encoded sorted, as Automerge has them.
+ message.need.sort_unstable();
message
});
let in_step = self.state.their_heads.as_ref() == Some(&doc.get_heads());
@@ -1224,9 +1226,11 @@ fn lost_beyond_sent(
if !lost {
return false;
}
- state.shared_heads = held_said.to_vec();
+ let mut held_said = held_said.to_vec();
+ held_said.sort_unstable();
+ state.shared_heads = held_said.clone();
state.their_have = Some(vec![sync::Have {
- last_sync: held_said.to_vec(),
+ last_sync: held_said,
bloom: sync::BloomFilter::default(),
}]);
true
@@ -1668,7 +1672,7 @@ mod tests {
}
/// What changes held back in screening lack is asked for (`lacks`), as Automerge
- /// asks for what the changes it holds back lack.
+ /// asks for what the changes it holds back lack, sorted as Automerge encodes them.
#[test]
fn a_message_asks_for_what_changes_held_back_lack() {
use crate::document::testing::change;
@@ -1676,8 +1680,12 @@ mod tests {
let (mut ours, mut theirs) = (Document::new(), Document::new());
change(&mut ours, |doc| doc.put(ROOT, "early", 1).unwrap());
let (_, mut b) = in_step(&mut ours, &mut theirs);
- change(&mut ours, |doc| doc.put(ROOT, "lacking", 2).unwrap());
- let lacking = ours.get_heads();
+ let mut lacking = Vec::new();
+ for n in 0..3 {
+ change(&mut ours, |doc| doc.put(ROOT, "lacking", n).unwrap());
+ lacking.push(ours.get_heads()[0]);
+ }
+ lacking.sort_unstable_by(|a, b| b.cmp(a));
change(&mut ours, |doc| doc.put(ROOT, "later", 3).unwrap());
b.pull_from(ours.get_heads());
b.lacks(lacking.clone());