From b979dee957eb423cef7b8ce97f544491f3ee2412 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 15 Jan 2025 12:27:40 +0000 Subject: [PATCH] fix(tests): Fix a flaky test by marking a room's members as synced. This is intended to prevent the test `test_when_user_in_verification_violation_becomes_verified_we_report_it` flaking. I found that sometimes when it called `Room::members` the result was empty due to it trying to fetch the answer from the server. This change prevents that behaviour. I don't know why the behaviour was inconsistent before. --- crates/matrix-sdk-base/src/rooms/normal.rs | 11 +++++++++++ crates/matrix-sdk/src/room/identity_status_changes.rs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/crates/matrix-sdk-base/src/rooms/normal.rs b/crates/matrix-sdk-base/src/rooms/normal.rs index 3a1b8a61d75..b393ddac9f1 100644 --- a/crates/matrix-sdk-base/src/rooms/normal.rs +++ b/crates/matrix-sdk-base/src/rooms/normal.rs @@ -391,6 +391,17 @@ impl Room { self.inner.read().members_synced } + /// Mark this Room as holding all member information. + /// + /// Useful in tests if we want to persuade the Room not to sync when asked + /// about its members. + #[cfg(feature = "testing")] + pub fn mark_members_synced(&self) { + self.inner.update(|info| { + info.members_synced = true; + }); + } + /// Mark this Room as still missing member information. pub fn mark_members_missing(&self) { self.inner.update_if(|info| { diff --git a/crates/matrix-sdk/src/room/identity_status_changes.rs b/crates/matrix-sdk/src/room/identity_status_changes.rs index 6e7a8602d39..7c86905a306 100644 --- a/crates/matrix-sdk/src/room/identity_status_changes.rs +++ b/crates/matrix-sdk/src/room/identity_status_changes.rs @@ -917,6 +917,8 @@ mod tests { .build_sync_response(); client.process_sync(create_room_sync_response).await.unwrap(); let room = client.get_room(&DEFAULT_TEST_ROOM_ID).expect("Room should exist"); + room.inner.mark_members_synced(); + assert_eq!(room.state(), RoomState::Joined); assert_eq!( *room