Skip to content

Commit 5176025

Browse files
committed
test: add group consistency bug test
1 parent b74ff27 commit 5176025

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/chat.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7711,6 +7711,53 @@ mod tests {
77117711
self_chat.set_draft(&alice, Some(&mut msg)).await.unwrap();
77127712
let draft2 = self_chat.get_draft(&alice).await?.unwrap();
77137713
assert_eq!(draft1.timestamp_sort, draft2.timestamp_sort);
7714+
7715+
Ok(())
7716+
}
7717+
7718+
/// Test group consistency.
7719+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7720+
async fn test_add_member_bug() -> Result<()> {
7721+
let mut tcm = TestContextManager::new();
7722+
7723+
let alice = &tcm.alice().await;
7724+
let bob = &tcm.bob().await;
7725+
7726+
let alice_bob_contact_id = Contact::create(alice, "Bob", "[email protected]").await?;
7727+
let alice_fiona_contact_id = Contact::create(alice, "Fiona", "[email protected]").await?;
7728+
7729+
// Create a group.
7730+
let alice_chat_id =
7731+
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
7732+
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
7733+
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7734+
7735+
// Promote the group.
7736+
let alice_sent_msg = alice
7737+
.send_text(alice_chat_id, "Hi! I created a group.")
7738+
.await;
7739+
let bob_received_msg = bob.recv_msg(&alice_sent_msg).await;
7740+
7741+
let bob_chat_id = bob_received_msg.get_chat_id();
7742+
bob_chat_id.accept(&bob).await?;
7743+
7744+
// Alice removes Fiona from the chat.
7745+
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7746+
let _alice_sent_add_msg = alice.pop_sent_msg().await;
7747+
7748+
SystemTime::shift(Duration::from_secs(3600));
7749+
7750+
// Bob sends a message
7751+
// to Alice and Fiona because he still has not received
7752+
// a message about Fiona being removed.
7753+
let bob_sent_msg = bob.send_text(bob_chat_id, "Hi Alice!").await;
7754+
7755+
// Alice receives a message.
7756+
// This should not add Fiona back.
7757+
let _alice_received_msg = alice.recv_msg(&bob_sent_msg).await;
7758+
7759+
assert_eq!(get_chat_contacts(alice, alice_chat_id).await?.len(), 2);
7760+
77147761
Ok(())
77157762
}
77167763
}

0 commit comments

Comments
 (0)