chore: fix flaky tests

This commit is contained in:
Bartosz Sypytkowski 2024-10-30 12:44:55 +01:00
parent c003044e0e
commit 31db4cf84f
4 changed files with 11 additions and 5 deletions

View File

@ -273,7 +273,7 @@ impl CollabGroup {
let message = AwarenessSync::new( let message = AwarenessSync::new(
state.object_id.clone(), state.object_id.clone(),
Message::Awareness(update.data).encode_v1(), Message::Awareness(update.data).encode_v1(),
sender.clone(), CollabOrigin::Empty,
); );
for mut e in state.subscribers.iter_mut() { for mut e in state.subscribers.iter_mut() {
let subscription = e.value_mut(); let subscription = e.value_mut();

View File

@ -24,7 +24,7 @@ async fn viewing_document_editing_users_test() {
let owner_uid = owner.uid().await; let owner_uid = owner.uid().await;
let clients = owner.get_connect_users(&object_id).await; let clients = owner.get_connect_users(&object_id).await;
assert_eq!(clients.len(), 1); assert_eq!(clients.len(), 1, "guest shouldn't be connected yet");
assert_eq!(clients[0], owner_uid); assert_eq!(clients[0], owner_uid);
owner owner
@ -39,6 +39,7 @@ async fn viewing_document_editing_users_test() {
.open_collab(&workspace_id, &object_id, collab_type) .open_collab(&workspace_id, &object_id, collab_type)
.await; .await;
guest.wait_object_sync_complete(&object_id).await.unwrap(); guest.wait_object_sync_complete(&object_id).await.unwrap();
sleep(Duration::from_secs(1)).await;
// after guest open the collab, it will emit an awareness that contains the user id of guest. // after guest open the collab, it will emit an awareness that contains the user id of guest.
// This awareness will be sent to the server. Server will broadcast the awareness to all the clients // This awareness will be sent to the server. Server will broadcast the awareness to all the clients
@ -50,7 +51,7 @@ async fn viewing_document_editing_users_test() {
let mut expected_clients = [owner_uid, guest_uid]; let mut expected_clients = [owner_uid, guest_uid];
expected_clients.sort(); expected_clients.sort();
assert_eq!(clients.len(), 2); assert_eq!(clients.len(), 2, "expected owner and member connected");
assert_eq!(clients, expected_clients); assert_eq!(clients, expected_clients);
// simulate the guest close the collab // simulate the guest close the collab
guest.clean_awareness_state(&object_id).await; guest.clean_awareness_state(&object_id).await;
@ -58,7 +59,7 @@ async fn viewing_document_editing_users_test() {
sleep(Duration::from_secs(5)).await; sleep(Duration::from_secs(5)).await;
guest.wait_object_sync_complete(&object_id).await.unwrap(); guest.wait_object_sync_complete(&object_id).await.unwrap();
let clients = owner.get_connect_users(&object_id).await; let clients = owner.get_connect_users(&object_id).await;
assert_eq!(clients.len(), 1); assert_eq!(clients.len(), 1, "expected only owner connected");
assert_eq!(clients[0], owner_uid); assert_eq!(clients[0], owner_uid);
// simulate the guest open the collab again // simulate the guest open the collab again

View File

@ -46,7 +46,7 @@ async fn run_multiple_text_edits() {
// run test scenario // run test scenario
let collab = writer.collabs.get(&object_id).unwrap().collab.clone(); let collab = writer.collabs.get(&object_id).unwrap().collab.clone();
let expected = test_scenario.execute(collab, 50_000).await; let expected = test_scenario.execute(collab, 40_000).await;
// wait for the writer to complete sync // wait for the writer to complete sync
writer.wait_object_sync_complete(&object_id).await.unwrap(); writer.wait_object_sync_complete(&object_id).await.unwrap();

View File

@ -134,7 +134,12 @@ impl TestScenario {
} }
pub async fn execute(&self, collab: CollabRef, step_count: usize) -> String { pub async fn execute(&self, collab: CollabRef, step_count: usize) -> String {
let mut i = 0;
for t in self.txns.iter().take(step_count) { for t in self.txns.iter().take(step_count) {
i += 1;
if i % 10_000 == 0 {
tracing::trace!("Executed {}/{} steps", i, step_count);
}
let mut lock = collab.write().await; let mut lock = collab.write().await;
let collab = lock.borrow_mut(); let collab = lock.borrow_mut();
let mut txn = collab.context.transact_mut(); let mut txn = collab.context.transact_mut();