diff --git a/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs b/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs index 314c82f98d0..6bce878c555 100644 --- a/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs +++ b/testing/matrix-sdk-integration-testing/src/tests/room_privacy.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::time::Duration; + use assert_matches2::assert_matches; use assign::assign; use matrix_sdk::{ @@ -29,10 +31,13 @@ use matrix_sdk::{ RoomHistoryVisibilityEventContent, }, }, + serde::Raw, RoomAliasId, }, }; +use matrix_sdk_base::ruma::events::room::canonical_alias::SyncRoomCanonicalAliasEvent; use rand::random; +use tokio::sync::mpsc::unbounded_channel; use crate::helpers::TestClientBuilder; @@ -109,8 +114,14 @@ async fn test_publishing_room_alias() -> anyhow::Result<()> { .update_canonical_alias(Some(room_alias.clone()), vec![alt_alias.clone()]) .await?; - // Give some time for the sync to run - tokio::time::sleep(tokio::time::Duration::from_secs(2)).await; + // Wait until we receive the canonical alias event through sync + let (tx, mut rx) = unbounded_channel(); + let handle = room.add_event_handler(move |_: Raw| { + let _ = tx.send(()); + async {} + }); + let _ = tokio::time::timeout(Duration::from_secs(2), rx.recv()).await?; + client.remove_event_handler(handle); // And we can check it actually changed the aliases let canonical_alias = room.canonical_alias();