Skip to content

Commit d6f0635

Browse files
committed
chore: clippy + review feedback
1 parent ea2826a commit d6f0635

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

crates/matrix-sdk-ui/src/encryption_sync/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ use tracing::{debug, trace};
4646
pub struct EncryptionSyncPermit(());
4747

4848
impl EncryptionSyncPermit {
49-
/// Create a new [`EncryptionSyncPermit`].
50-
///
51-
/// Note: in general, you'd want to get such a permit from a [`SyncService`]
52-
/// instead of creating it yourself.
53-
pub fn new() -> Self {
49+
pub(crate) fn new() -> Self {
5450
Self(())
5551
}
5652
}
5753

54+
impl EncryptionSyncPermit {
55+
/// Test-only.
56+
#[doc(hidden)]
57+
pub fn new_for_testing() -> Self {
58+
Self::new()
59+
}
60+
}
61+
5862
/// Should the `EncryptionSync` make use of locking?
5963
pub enum WithLocking {
6064
Yes,

crates/matrix-sdk-ui/src/notification_client.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,36 @@ impl NotificationClient {
192192
// means we were racing against the encryption sync. Wait a bit, attempt to
193193
// decrypt, and carry on.
194194

195-
let mut wait = 200; // we get to wait 7 times that number at most.
195+
// We repeat the sleep 3 times at most, each iteration we
196+
// double the amount of time waited, so overall we may wait up to 7 times this
197+
// amount.
198+
let mut wait = 200;
199+
196200
for _ in 0..3 {
201+
tracing::debug!("Sync running in background while getting a notification; waiting for decryption…");
202+
197203
tokio::time::sleep(Duration::from_millis(wait)).await; // heuristics~~~
204+
//
198205
let new_event = room.decrypt_event(raw_event.cast_ref()).await?;
206+
199207
if !is_event_encrypted(
200208
new_event
201209
.event
202210
.deserialize()
203211
.map_err(|_| Error::InvalidRumaEvent)?
204212
.event_type(),
205213
) {
214+
tracing::debug!("Waiting succeeded!");
206215
return Ok(Some(new_event));
207216
}
217+
208218
wait *= 2;
209219
}
210220

211221
// We couldn't decrypt the event after waiting a few times, abort.
222+
tracing::debug!(
223+
"Timeout waiting for the sync service to decrypt the notification event."
224+
);
212225
return Ok(None);
213226
}
214227
}

crates/matrix-sdk-ui/tests/integration/encryption_sync.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
async fn test_smoke_encryption_sync_works() -> anyhow::Result<()> {
1818
let (client, server) = logged_in_client().await;
1919

20-
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
20+
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
2121
let sync_permit_guard = sync_permit.clone().lock_owned().await;
2222
let encryption_sync =
2323
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
@@ -111,7 +111,6 @@ async fn test_smoke_encryption_sync_works() -> anyhow::Result<()> {
111111
assert!(stream.next().await.is_none());
112112

113113
// Start a new sync.
114-
drop(stream);
115114
let sync_permit_guard = sync_permit.clone().lock_owned().await;
116115
let stream = encryption_sync.sync(sync_permit_guard);
117116
pin_mut!(stream);
@@ -198,7 +197,7 @@ async fn test_encryption_sync_one_fixed_iteration() -> anyhow::Result<()> {
198197

199198
let _guard = setup_mocking_sliding_sync_server(&server).await;
200199

201-
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
200+
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
202201
let sync_permit_guard = sync_permit.lock_owned().await;
203202
let encryption_sync =
204203
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
@@ -230,7 +229,7 @@ async fn test_encryption_sync_two_fixed_iterations() -> anyhow::Result<()> {
230229

231230
let _guard = setup_mocking_sliding_sync_server(&server).await;
232231

233-
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
232+
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
234233
let sync_permit_guard = sync_permit.lock_owned().await;
235234
let encryption_sync =
236235
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
@@ -265,7 +264,7 @@ async fn test_encryption_sync_two_fixed_iterations() -> anyhow::Result<()> {
265264
async fn test_encryption_sync_always_reloads_todevice_token() -> anyhow::Result<()> {
266265
let (client, server) = logged_in_client().await;
267266

268-
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
267+
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
269268
let sync_permit_guard = sync_permit.lock_owned().await;
270269
let encryption_sync =
271270
EncryptionSync::new("tests".to_owned(), client.clone(), None, WithLocking::Yes).await?;

0 commit comments

Comments
 (0)