From 95fb8698528dc4149056f7cb6e9e1b67fe2d4cc9 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 4 Nov 2026 21:38:19 +0100 Subject: tests count the changes sent --- src/document/sync.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/document/sync.rs b/src/document/sync.rs index f2d6669..695f272 100644 --- a/src/document/sync.rs +++ b/src/document/sync.rs @@ -918,8 +918,10 @@ mod tests { a.receive(&mut ours, decode(&ask).unwrap()).unwrap(); a.resend_if_needed(&ours, "b"); + let sent_before = a.state.sent_hashes.clone(); let again = send(&mut a, &ours); - let carried = sync::Message::decode(&again.0).unwrap().changes.len(); + // What the message carried: the changes it added to what a counts as sent. + let carried = a.state.sent_hashes.difference(&sent_before).count(); assert_eq!( carried, 1, "only the first again, not the second, on its way" @@ -956,9 +958,9 @@ mod tests { // As `resend_if_needed` does when the peer needs what we sent. a.state.sent_hashes.clear(); change(&mut ours, |doc| doc.put(ROOT, "news", 6).unwrap()); - let message = a.generate(&ours, now, bytes).unwrap(); - let carried = sync::Message::decode(&message.0).unwrap().changes.len(); - assert_eq!(carried, 1, "only the news"); + a.generate(&ours, now, bytes).unwrap(); + // What the message carried: what a counts as sent now (nothing before). + assert_eq!(a.state.sent_hashes.len(), 1, "only the news"); } /// Three messages arrive in reverse order: once the first is in, all three apply, @@ -986,7 +988,7 @@ mod tests { } assert_eq!(theirs.get_heads(), ours.get_heads()); if let Some(answer) = b.generate(&theirs, now, bytes) { - let carried = sync::Message::decode(&answer.0).unwrap().changes.len(); + let (carried, _) = decode(&answer).unwrap().sizes(); assert_eq!(carried, 0, "a's own changes went back to it"); } } -- cgit v1.3.1