From 5365fd2149dc7c0991e10d8c8f2c568b5ce67090 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Sat, 21 Oct 2023 03:05:57 -0700 Subject: [PATCH] WIP: Add test for panic, temporarily rollback synchronization changes --- crates/call/src/call.rs | 17 ++-- crates/collab/src/tests.rs | 4 + crates/collab/src/tests/integration_tests.rs | 90 +++++++++++++++++++- 3 files changed, 102 insertions(+), 9 deletions(-) diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index 98233e1a10b896073b68f91fa4e52d70aa649f3f..dbd61431dc7866bbd84d19dce5caf4981b42d02a 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -66,6 +66,7 @@ impl OneAtATime { pub struct ActiveCall { room: Option<(ModelHandle, Vec)>, pending_room_creation: Option, Arc>>>>, + _join_debouncer: OneAtATime, location: Option>, pending_invites: HashSet, incoming_call: ( @@ -74,7 +75,6 @@ pub struct ActiveCall { ), client: Arc, user_store: ModelHandle, - _join_debouncer: OneAtATime, _subscriptions: Vec, } @@ -289,13 +289,12 @@ impl ActiveCall { let room_id = call.room_id.clone(); let client = self.client.clone(); let user_store = self.user_store.clone(); - let join = self - ._join_debouncer - .spawn(cx, move |cx| Room::join(room_id, client, user_store, cx)); + let join = + cx.spawn(|this, cx| async move { Room::join(room_id, client, user_store, cx).await }); cx.spawn(|this, mut cx| async move { let room = join.await?; - this.update(&mut cx, |this, cx| this.set_room(room.clone(), cx)) + this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)) .await?; this.update(&mut cx, |this, cx| { this.report_call_event("accept incoming", cx) @@ -333,18 +332,20 @@ impl ActiveCall { let client = self.client.clone(); let user_store = self.user_store.clone(); - let join = self._join_debouncer.spawn(cx, move |cx| async move { + let join = cx.spawn(|this, cx| async move { Room::join_channel(channel_id, client, user_store, cx).await }); + // self._join_debouncer.spawn(cx, move |cx| async move {}); + cx.spawn(move |this, mut cx| async move { let room = join.await?; - this.update(&mut cx, |this, cx| this.set_room(room.clone(), cx)) + this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)) .await?; this.update(&mut cx, |this, cx| { this.report_call_event("join channel", cx) }); - Ok(room) + Ok(Some(room)) }) } diff --git a/crates/collab/src/tests.rs b/crates/collab/src/tests.rs index e78bbe3466318cfc44fbcf298cef65a86350a0b8..811cb910e6bca10fc239f10bdbc49eb8540e069a 100644 --- a/crates/collab/src/tests.rs +++ b/crates/collab/src/tests.rs @@ -39,3 +39,7 @@ fn room_participants(room: &ModelHandle, cx: &mut TestAppContext) -> RoomP RoomParticipants { remote, pending } }) } + +fn channel_id(room: &ModelHandle, cx: &mut TestAppContext) -> u64 { + cx.read(|cx| room.read(cx).channel_id().unwrap()) +} diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index d6d449fd476b0d6f967641268bf1798a21ccf81d..3bc4f17f85fb643e6fe9e5f126e0b5e0f4826c31 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -1,6 +1,6 @@ use crate::{ rpc::{CLEANUP_TIMEOUT, RECONNECT_TIMEOUT}, - tests::{room_participants, RoomParticipants, TestClient, TestServer}, + tests::{channel_id, room_participants, RoomParticipants, TestClient, TestServer}, }; use call::{room, ActiveCall, ParticipantLocation, Room}; use client::{User, RECEIVE_TIMEOUT}; @@ -469,6 +469,94 @@ async fn test_calling_multiple_users_simultaneously( ); } +#[gpui::test(iterations = 10)] +async fn test_joining_channels_and_calling_multiple_users_simultaneously( + deterministic: Arc, + cx_a: &mut TestAppContext, + cx_b: &mut TestAppContext, + cx_c: &mut TestAppContext, +) { + deterministic.forbid_parking(); + let mut server = TestServer::start(&deterministic).await; + + let client_a = server.create_client(cx_a, "user_a").await; + let client_b = server.create_client(cx_b, "user_b").await; + let client_c = server.create_client(cx_c, "user_c").await; + server + .make_contacts(&mut [(&client_a, cx_a), (&client_b, cx_b), (&client_c, cx_c)]) + .await; + + let channel_1 = server + .make_channel( + "channel1", + None, + (&client_a, cx_a), + &mut [(&client_b, cx_b), (&client_c, cx_c)], + ) + .await; + + let channel_2 = server + .make_channel( + "channel2", + None, + (&client_a, cx_a), + &mut [(&client_b, cx_b), (&client_c, cx_c)], + ) + .await; + + let active_call_a = cx_a.read(ActiveCall::global); + + // Simultaneously join channel 1 and then channel 2 + active_call_a + .update(cx_a, |call, cx| call.join_channel(channel_1, cx)) + .detach(); + let join_channel_2 = active_call_a.update(cx_a, |call, cx| call.join_channel(channel_2, cx)); + + join_channel_2.await.unwrap(); + + let room_a = active_call_a.read_with(cx_a, |call, _| call.room().unwrap().clone()); + deterministic.run_until_parked(); + + assert_eq!(channel_id(&room_a, cx_a), channel_2); + + todo!(); + + // Leave the room + active_call_a + .update(cx_a, |call, cx| { + let hang_up = call.hang_up(cx); + hang_up + }) + .await + .unwrap(); + + // Simultaneously join channel 1 and call user B and user C from client A. + let join_channel = active_call_a.update(cx_a, |call, cx| call.join_channel(channel_1, cx)); + + let b_invite = active_call_a.update(cx_a, |call, cx| { + call.invite(client_b.user_id().unwrap(), None, cx) + }); + let c_invite = active_call_a.update(cx_a, |call, cx| { + call.invite(client_c.user_id().unwrap(), None, cx) + }); + join_channel.await.unwrap(); + b_invite.await.unwrap(); + c_invite.await.unwrap(); + + let room_a = active_call_a.read_with(cx_a, |call, _| call.room().unwrap().clone()); + deterministic.run_until_parked(); + + assert_eq!( + room_participants(&room_a, cx_a), + RoomParticipants { + remote: Default::default(), + pending: vec!["user_b".to_string(), "user_c".to_string()] + } + ); + + assert_eq!(channel_id(&room_a, cx_a), channel_1); +} + #[gpui::test(iterations = 10)] async fn test_room_uniqueness( deterministic: Arc,