Skip to content

Commit 5fec0bf

Browse files
committed
test: add test_parallel_setup_contact
1 parent 63313a4 commit 5fec0bf

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/securejoin/securejoin_tests.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,56 @@ async fn test_parallel_securejoin() -> Result<()> {
893893

894894
Ok(())
895895
}
896+
897+
/// Tests Bob scanning setup contact QR codes of Alice and Fiona
898+
/// concurrently.
899+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
900+
async fn test_parallel_setup_contact() -> Result<()> {
901+
let mut tcm = TestContextManager::new();
902+
let alice = &tcm.alice().await;
903+
let bob = &tcm.bob().await;
904+
let fiona = &tcm.fiona().await;
905+
906+
// Bob scans Alice's QR code,
907+
// but Alice is offline and takes a while to respond.
908+
let alice_qr = get_securejoin_qr(alice, None).await?;
909+
join_securejoin(bob, &alice_qr).await?;
910+
let sent_alice_vc_request = bob.pop_sent_msg().await;
911+
912+
// Bob scans Fiona's QR code while SecureJoin
913+
// process with Alice is not finished.
914+
let fiona_qr = get_securejoin_qr(fiona, None).await?;
915+
join_securejoin(bob, &fiona_qr).await?;
916+
let sent_fiona_vc_request = bob.pop_sent_msg().await;
917+
918+
fiona.recv_msg_trash(&sent_fiona_vc_request).await;
919+
let sent_fiona_vc_auth_required = fiona.pop_sent_msg().await;
920+
921+
bob.recv_msg_trash(&sent_fiona_vc_auth_required).await;
922+
let sent_fiona_vc_request_with_auth = bob.pop_sent_msg().await;
923+
924+
fiona.recv_msg_trash(&sent_fiona_vc_request_with_auth).await;
925+
let sent_fiona_vc_contact_confirm = fiona.pop_sent_msg().await;
926+
927+
bob.recv_msg_trash(&sent_fiona_vc_contact_confirm).await;
928+
let bob_fiona_contact_id = bob.add_or_lookup_contact_id(fiona).await;
929+
let bob_fiona_contact = Contact::get_by_id(bob, bob_fiona_contact_id).await.unwrap();
930+
assert_eq!(bob_fiona_contact.is_verified(bob).await.unwrap(), true);
931+
932+
// Alice gets online and previously started SecureJoin process finishes.
933+
alice.recv_msg_trash(&sent_alice_vc_request).await;
934+
let sent_alice_vc_auth_required = alice.pop_sent_msg().await;
935+
936+
bob.recv_msg_trash(&sent_alice_vc_auth_required).await;
937+
let sent_alice_vc_request_with_auth = bob.pop_sent_msg().await;
938+
939+
alice.recv_msg_trash(&sent_alice_vc_request_with_auth).await;
940+
let sent_alice_vc_contact_confirm = alice.pop_sent_msg().await;
941+
942+
bob.recv_msg_trash(&sent_alice_vc_contact_confirm).await;
943+
let bob_alice_contact_id = bob.add_or_lookup_contact_id(alice).await;
944+
let bob_alice_contact = Contact::get_by_id(bob, bob_alice_contact_id).await.unwrap();
945+
assert_eq!(bob_alice_contact.is_verified(bob).await.unwrap(), true);
946+
947+
Ok(())
948+
}

0 commit comments

Comments
 (0)