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

Send msg db locked fix #1484

Closed
wants to merge 17 commits into from
Closed
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
60 changes: 59 additions & 1 deletion bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ mod tests {
Arc, Mutex,
},
};
use tokio::{sync::Notify, time::error::Elapsed};
use tokio::{sync::Notify, task::JoinSet, time::error::Elapsed};
use xmtp_common::tmp_path;
use xmtp_common::{wait_for_eq, wait_for_ok};
use xmtp_content_types::{read_receipt, text::TextCodec, ContentCodec};
Expand Down Expand Up @@ -5654,6 +5654,64 @@ mod tests {
));
}

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn test_can_send_parallel_messages() {
// Create two test clients
let alix = new_test_client().await;
let bo = new_test_client().await;

// Create a conversation between them
let alix_conversation = alix
.conversations()
.create_group(
vec![bo.account_address.clone()],
FfiCreateGroupOptions::default(),
)
.await
.unwrap();

// Create JoinSet for parallel tasks
let mut tasks = JoinSet::new();

// Spawn tasks for sending messages in parallel
for i in 1..=6 {
let conversation = alix_conversation.clone();
let message = format!("Message {}", i);
tasks.spawn(async move { conversation.send(message.as_bytes().to_vec()).await });
}

// Collect results as they complete
let mut results = Vec::new();
while let Some(result) = tasks.join_next().await {
results.push(result.unwrap());
}

// Check each result and print any errors
for (i, result) in results.iter().enumerate() {
if let Err(e) = result {
// No longer erroring here: GroupError(Storage(DieselResult(DatabaseError(Unknown, "database is locked"))))
println!("Error sending message {}: {:?}", i + 1, e);
}
}

// Assert all messages were sent successfully
assert!(
results.into_iter().all(|r| r.is_ok()),
"Not all messages were sent successfully"
);

// Have Alix sync to get the messages
alix_conversation.sync().await.unwrap();

// Verify messages were received
let messages = alix_conversation
.find_messages(FfiListMessagesOptions::default())
.await
.unwrap();

assert_eq!(messages.len(), 7);
}

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