Applying multiple times leaves views equal

This commit is contained in:
Dave Hrycyszyn
2024-06-12 15:07:24 +01:00
parent 28e606ba51
commit 7bb672f4b8

View File

@@ -30,7 +30,6 @@ struct ListExample {
fn test_valid_updates() { fn test_valid_updates() {
// Insert to crdt.doc on local node, test applying the same operation to a remote node // Insert to crdt.doc on local node, test applying the same operation to a remote node
// and check that the view is the same // and check that the view is the same
let key = make_keypair(); let key = make_keypair();
let mut crdt = BaseCrdt::<ListExample>::new(&key); let mut crdt = BaseCrdt::<ListExample>::new(&key);
let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key); let _a = crdt.doc.list.insert(ROOT_ID, 'a').sign(&key);
@@ -42,14 +41,23 @@ fn test_valid_updates() {
let key2 = make_keypair(); let key2 = make_keypair();
let mut crdt2 = BaseCrdt::<ListExample>::new(&key2); let mut crdt2 = BaseCrdt::<ListExample>::new(&key2);
crdt2.apply(_a.clone()); crdt2.apply(_a.clone());
crdt2.apply(_a.clone());
crdt2.apply(_b); crdt2.apply(_b);
crdt2.apply(_c); crdt2.apply(_c.clone());
crdt2.apply(_a);
let _d = crdt2.doc.list.insert(_d.id(), 'c').sign(&key); // fix this in the morning
// Ok something is seriously wrong here. assert_eq!(
assert_eq!(crdt2.doc.list.view(), crdt.doc.list.view()); crdt2.doc.list.view(),
crdt.doc.list.view(),
"views should be equal"
);
crdt2.apply(_a.clone());
crdt2.apply(_a);
assert_eq!(
crdt.doc.list.view(),
crdt2.doc.list.view(),
"views are still equal after repeated applies"
);
} }
// case 2a + 2b // case 2a + 2b