Skip to content

Commit

Permalink
Add test to make sure commits work when out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhuaaa committed Jul 24, 2024
1 parent 7e2c673 commit b7543d9
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,66 @@ mod tests {
assert!(stream_messages.is_closed());
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_can_add_members_when_out_of_sync() {
let alix = new_test_client().await;
let bo = new_test_client().await;
let caro = new_test_client().await;
let davon = new_test_client().await;
let eri = new_test_client().await;
let frankie = new_test_client().await;

let alix_group = alix
.conversations()
.create_group(
vec![bo.account_address.clone()],
FfiCreateGroupOptions::default(),
)
.await
.unwrap();

bo.conversations().sync().await.unwrap();
let bo_group = bo.group(alix_group.id()).unwrap();

bo_group.send("bo1".as_bytes().to_vec()).await.unwrap();
alix_group.send("alix1".as_bytes().to_vec()).await.unwrap();

// Move the group forward by 3 epochs (as Alix's max_past_epochs is
// configured to 3) without Bo syncing
alix_group
.add_members(vec![
caro.account_address.clone(),
davon.account_address.clone(),
])
.await
.unwrap();
alix_group
.remove_members(vec![
caro.account_address.clone(),
davon.account_address.clone(),
])
.await
.unwrap();
alix_group
.add_members(vec![eri.account_address.clone()])
.await
.unwrap();

// Bo adds a member while 3 epochs behind
bo_group
.add_members(vec![frankie.account_address.clone()])
.await
.unwrap();

bo_group.sync().await.unwrap();
let bo_members = bo_group.list_members().unwrap();
assert_eq!(bo_members.len(), 4);

alix_group.sync().await.unwrap();
let alix_members = alix_group.list_members().unwrap();
assert_eq!(alix_members.len(), 4);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_can_send_message_when_out_of_sync() {
let alix = new_test_client().await;
Expand Down

0 comments on commit b7543d9

Please sign in to comment.