Skip to content

Commit d1595c0

Browse files
committed
test: add group consistency bug test
1 parent 46922d4 commit d1595c0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/chat.rs

+46
Original file line numberDiff line numberDiff line change
@@ -7652,4 +7652,50 @@ mod tests {
76527652

76537653
Ok(())
76547654
}
7655+
7656+
/// Test group consistency.
7657+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
7658+
async fn test_add_member_bug() -> Result<()> {
7659+
let mut tcm = TestContextManager::new();
7660+
7661+
let alice = &tcm.alice().await;
7662+
let bob = &tcm.bob().await;
7663+
7664+
let alice_bob_contact_id = Contact::create(alice, "Bob", "[email protected]").await?;
7665+
let alice_fiona_contact_id = Contact::create(alice, "Fiona", "[email protected]").await?;
7666+
7667+
// Create a group.
7668+
let alice_chat_id =
7669+
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
7670+
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
7671+
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7672+
7673+
// Promote the group.
7674+
let alice_sent_msg = alice
7675+
.send_text(alice_chat_id, "Hi! I created a group.")
7676+
.await;
7677+
let bob_received_msg = bob.recv_msg(&alice_sent_msg).await;
7678+
7679+
let bob_chat_id = bob_received_msg.get_chat_id();
7680+
bob_chat_id.accept(&bob).await?;
7681+
7682+
// Alice removes Fiona from the chat.
7683+
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
7684+
let _alice_sent_add_msg = alice.pop_sent_msg().await;
7685+
7686+
SystemTime::shift(Duration::from_secs(3600));
7687+
7688+
// Bob sends a message
7689+
// to Alice and Fiona because he still has not received
7690+
// a message about Fiona being removed.
7691+
let bob_sent_msg = bob.send_text(bob_chat_id, "Hi Alice!").await;
7692+
7693+
// Alice receives a message.
7694+
// This should not add Fiona back.
7695+
let _alice_received_msg = alice.recv_msg(&bob_sent_msg).await;
7696+
7697+
assert_eq!(get_chat_contacts(alice, alice_chat_id).await?.len(), 2);
7698+
7699+
Ok(())
7700+
}
76557701
}

0 commit comments

Comments
 (0)