From 6dbdffd36eed137de7d6fe878ff6c58dfbab86cb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 5 Sep 2025 13:45:27 +0200 Subject: [PATCH] refactor(ui): `sync_service::State` no longer implements `PartialEq`. This patch removes the `PartialEq` implementation on `sync_service::State`. It was only used for test purposes. Outside that, it doesn't make sense. --- crates/matrix-sdk-ui/src/sync_service.rs | 6 ++++- .../tests/integration/sync_service.rs | 27 ++++++++++--------- crates/matrix-sdk/src/test_utils/mod.rs | 3 +++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index 31ca10c12..db8d97c13 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -58,16 +58,20 @@ use crate::{ /// [`State::Error`] (in case any of the underlying syncs ran into an error). /// /// This can be observed with [`SyncService::state`]. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug)] pub enum State { /// The service hasn't ever been started yet, or has been stopped. Idle, + /// The underlying syncs are properly running in the background. Running, + /// Any of the underlying syncs has terminated gracefully (i.e. be stopped). Terminated, + /// Any of the underlying syncs has ran into an error. Error, + /// The service has entered offline mode. This state will only be entered if /// the [`SyncService`] has been built with the /// [`SyncServiceBuilder::with_offline_mode`] setting. diff --git a/crates/matrix-sdk-ui/tests/integration/sync_service.rs b/crates/matrix-sdk-ui/tests/integration/sync_service.rs index f61984372..a57c5d0cc 100644 --- a/crates/matrix-sdk-ui/tests/integration/sync_service.rs +++ b/crates/matrix-sdk-ui/tests/integration/sync_service.rs @@ -17,14 +17,15 @@ use std::{ time::Duration, }; +use assert_matches::assert_matches; use matrix_sdk::{ - assert_next_eq_with_timeout, + assert_next_matches_with_timeout, test_utils::{logged_in_client_with_server, mocks::MatrixMockServer}, }; use matrix_sdk_test::async_test; use matrix_sdk_ui::sync_service::{State, SyncService}; use serde_json::json; -use stream_assert::{assert_next_eq, assert_next_matches, assert_pending}; +use stream_assert::{assert_next_matches, assert_pending}; use wiremock::{Match as _, Mock, MockGuard, MockServer, Request, ResponseTemplate}; use crate::sliding_sync::{PartialSlidingSyncRequest, SlidingSyncMatcher}; @@ -74,7 +75,7 @@ async fn test_sync_service_state() -> anyhow::Result<()> { let mut state_stream = sync_service.state(); // At first, the sync service is sleeping. - assert_eq!(state_stream.get(), State::Idle); + assert_matches!(state_stream.get(), State::Idle); assert!(server.received_requests().await.unwrap().is_empty()); assert!(!sync_service.is_supervisor_running().await); assert!(sync_service.try_get_encryption_sync_permit().is_some()); @@ -224,13 +225,13 @@ async fn test_sync_service_offline_mode() { let _versions_guard = mock_server.mock_versions().error500().mount_as_scoped().await; sync_service.start().await; - assert_next_eq!(states, State::Running); - assert_next_eq_with_timeout!(states, State::Offline, 2000 ms, "We should have entered the offline mode"); + assert_next_matches!(states, State::Running); + assert_next_matches_with_timeout!(states, 2000, State::Offline); } mock_server.mock_versions().ok().expect(1..).mount().await; - assert_next_eq_with_timeout!(states, State::Running, 1000 ms, "We should have continued to sync"); + assert_next_matches_with_timeout!(states, 1000, State::Running); } #[async_test] @@ -249,11 +250,11 @@ async fn test_sync_service_offline_mode_stopping() { mock_server.mock_versions().error500().mount().await; sync_service.start().await; - assert_next_eq!(states, State::Running); + assert_next_matches!(states, State::Running); - assert_next_eq_with_timeout!(states, State::Offline, 2000 ms, "We should have entered the offline mode"); + assert_next_matches_with_timeout!(states, 2000, State::Offline); sync_service.stop().await; - assert_next_eq_with_timeout!(states, State::Idle, 2000 ms, "We should have entered the idle mode"); + assert_next_matches_with_timeout!(states, 2000, State::Idle); } #[async_test] @@ -271,11 +272,11 @@ async fn test_sync_service_offline_mode_restarting() { mock_server.mock_versions().error500().mount().await; sync_service.start().await; - assert_next_eq!(states, State::Running); - assert_next_eq_with_timeout!(states, State::Offline, 2000 ms, "We should have entered the offline mode"); + assert_next_matches!(states, State::Running); + assert_next_matches_with_timeout!(states, 2000, State::Offline); sync_service.start().await; - assert_next_eq_with_timeout!(states, State::Running, 2000 ms, "We should have entered the running mode"); - assert_next_eq_with_timeout!(states, State::Offline, 2000 ms, "We should have entered the offline mode again"); + assert_next_matches_with_timeout!(states, 2000, State::Running); + assert_next_matches_with_timeout!(states, 2000, State::Offline); } diff --git a/crates/matrix-sdk/src/test_utils/mod.rs b/crates/matrix-sdk/src/test_utils/mod.rs index 01851cd6d..66aaba7c2 100644 --- a/crates/matrix-sdk/src/test_utils/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mod.rs @@ -158,6 +158,9 @@ macro_rules! assert_next_matches_with_timeout { ($stream:expr, $pat:pat => $arm:expr) => { $crate::assert_next_matches_with_timeout!($stream, 100, $pat => $arm) }; + ($stream:expr, $timeout_ms:expr, $pat:pat) => { + $crate::assert_next_matches_with_timeout!($stream, $timeout_ms, $pat => {}) + }; ($stream:expr, $timeout_ms:expr, $pat:pat => $arm:expr) => { match $crate::assert_next_with_timeout!(&mut $stream, $timeout_ms) { $pat => $arm,