MCPcopy Create free account
hub / github.com/chatmail/core / test_parallel_securejoin

Function test_parallel_securejoin

src/securejoin/securejoin_tests.rs:863–910  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

861/// from the same Alice at the same time.
862#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
863async fn test_parallel_securejoin() -> Result<()> {
864 let mut tcm = TestContextManager::new();
865 let alice = &tcm.alice().await;
866 let bob = &tcm.bob().await;
867
868 let alice_chat1_id = chat::create_group(alice, "First chat").await?;
869 let alice_chat2_id = chat::create_group(alice, "Second chat").await?;
870
871 let qr1 = get_securejoin_qr(alice, Some(alice_chat1_id)).await?;
872 let qr2 = get_securejoin_qr(alice, Some(alice_chat2_id)).await?;
873
874 // Bob scans both QR codes.
875 let bob_chat1_id = join_securejoin(bob, &qr1).await?;
876 let sent_vg_request1 = bob.pop_sent_msg().await;
877
878 let bob_chat2_id = join_securejoin(bob, &qr2).await?;
879 let sent_vg_request2 = bob.pop_sent_msg().await;
880
881 // Alice receives two `vg-request` messages
882 // and sends back two `vg-auth-required` messages.
883 alice.recv_msg_trash(&sent_vg_request1).await;
884 let sent_vg_auth_required1 = alice.pop_sent_msg().await;
885
886 alice.recv_msg_trash(&sent_vg_request2).await;
887 let _sent_vg_auth_required2 = alice.pop_sent_msg().await;
888
889 // Bob receives first `vg-auth-required` message.
890 // Bob has two securejoin processes started,
891 // so he should send two `vg-request-with-auth` messages.
892 bob.recv_msg_trash(&sent_vg_auth_required1).await;
893
894 // Bob sends `vg-request-with-auth` messages.
895 let sent_vg_request_with_auth2 = bob.pop_sent_msg().await;
896 let sent_vg_request_with_auth1 = bob.pop_sent_msg().await;
897
898 // Alice receives both `vg-request-with-auth` messages.
899 alice.recv_msg_trash(&sent_vg_request_with_auth1).await;
900 let sent_vg_member_added1 = alice.pop_sent_msg().await;
901 let joined_chat_id1 = bob.recv_msg(&sent_vg_member_added1).await.chat_id;
902 assert_eq!(joined_chat_id1, bob_chat1_id);
903
904 alice.recv_msg_trash(&sent_vg_request_with_auth2).await;
905 let sent_vg_member_added2 = alice.pop_sent_msg().await;
906 let joined_chat_id2 = bob.recv_msg(&sent_vg_member_added2).await.chat_id;
907 assert_eq!(joined_chat_id2, bob_chat2_id);
908
909 Ok(())
910}
911
912/// Tests Bob scanning setup contact QR codes of Alice and Fiona
913/// concurrently.

Callers

nothing calls this directly

Calls 8

get_securejoin_qrFunction · 0.85
join_securejoinFunction · 0.85
aliceMethod · 0.80
bobMethod · 0.80
pop_sent_msgMethod · 0.80
recv_msg_trashMethod · 0.80
recv_msgMethod · 0.80
create_groupFunction · 0.50

Tested by

no test coverage detected