Skip to content

Commit

Permalink
fix(tests): Fix a flaky test by marking a room's members as synced.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andybalaam committed Jan 15, 2025
1 parent fe3cc09 commit 8bd9431
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/matrix-sdk-base/src/rooms/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 2 additions & 0 deletions crates/matrix-sdk/src/room/identity_status_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bd9431

Please sign in to comment.