Skip to content

Commit

Permalink
chore: fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Horusiath committed Nov 5, 2024
1 parent 5388d41 commit 99203cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion services/appflowy-collaborate/src/group/group_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl CollabGroup {
let message = AwarenessSync::new(
state.object_id.clone(),
Message::Awareness(update.data).encode_v1(),
sender.clone(),
CollabOrigin::Empty,
);
for mut e in state.subscribers.iter_mut() {
let subscription = e.value_mut();
Expand Down
7 changes: 4 additions & 3 deletions tests/collab/awareness_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn viewing_document_editing_users_test() {

let owner_uid = owner.uid().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);

owner
Expand All @@ -39,6 +39,7 @@ async fn viewing_document_editing_users_test() {
.open_collab(&workspace_id, &object_id, collab_type)
.await;
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.
// This awareness will be sent to the server. Server will broadcast the awareness to all the clients
Expand All @@ -50,15 +51,15 @@ async fn viewing_document_editing_users_test() {
let mut expected_clients = [owner_uid, guest_uid];
expected_clients.sort();

assert_eq!(clients.len(), 2);
assert_eq!(clients.len(), 2, "expected owner and member connected");
assert_eq!(clients, expected_clients);
// simulate the guest close the collab
guest.clean_awareness_state(&object_id).await;
// sleep 5 second to make sure the awareness observe callback is called
sleep(Duration::from_secs(5)).await;
guest.wait_object_sync_complete(&object_id).await.unwrap();
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);

// simulate the guest open the collab again
Expand Down
2 changes: 1 addition & 1 deletion tests/collab/stress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn run_multiple_text_edits() {

// run test scenario
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
writer.wait_object_sync_complete(&object_id).await.unwrap();
Expand Down
5 changes: 5 additions & 0 deletions tests/collab/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ impl TestScenario {
}

pub async fn execute(&self, collab: CollabRef, step_count: usize) -> String {
let mut i = 0;
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 collab = lock.borrow_mut();
let mut txn = collab.context.transact_mut();
Expand Down

0 comments on commit 99203cc

Please sign in to comment.