Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add group consistency bug test #6021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7652,4 +7652,50 @@ mod tests {

Ok(())
}

/// Test group consistency.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_add_member_bug() -> Result<()> {
let mut tcm = TestContextManager::new();

let alice = &tcm.alice().await;
let bob = &tcm.bob().await;

let alice_bob_contact_id = Contact::create(alice, "Bob", "bob@example.net").await?;
let alice_fiona_contact_id = Contact::create(alice, "Fiona", "fiona@example.net").await?;

// Create a group.
let alice_chat_id =
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;

// Promote the group.
let alice_sent_msg = alice
.send_text(alice_chat_id, "Hi! I created a group.")
.await;
let bob_received_msg = bob.recv_msg(&alice_sent_msg).await;

let bob_chat_id = bob_received_msg.get_chat_id();
bob_chat_id.accept(&bob).await?;

// Alice removes Fiona from the chat.
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
let _alice_sent_add_msg = alice.pop_sent_msg().await;

SystemTime::shift(Duration::from_secs(3600));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time shift bypasses the fix introduced in #5376 to fix #5366


// Bob sends a message
// to Alice and Fiona because he still has not received
// a message about Fiona being removed.
let bob_sent_msg = bob.send_text(bob_chat_id, "Hi Alice!").await;

// Alice receives a message.
// This should not add Fiona back.
let _alice_received_msg = alice.recv_msg(&bob_sent_msg).await;

assert_eq!(get_chat_contacts(alice, alice_chat_id).await?.len(), 2);

Ok(())
}
}
Loading