Skip to content

Commit 237c025

Browse files
BillCarsonFrpoljarbnjbvr
authored
fix(tests): tweak a flaky test to make it more stable + logs (#4968)
Tentative fix for #4832 Tweaked a bit the timings and added more logging in the UTD manager to see what is happening exactly in case it is still flaky. Signed-off-by: Damir Jelić <poljar@termina.org.uk> Co-authored-by: Damir Jelić <poljar@termina.org.uk> Co-authored-by: Benjamin Bouvier <benjamin@bouvier.cc>
1 parent f763d36 commit 237c025

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

crates/matrix-sdk-ui/src/timeline/tests/encryption.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ async fn test_false_positive_late_decryption_regression() {
194194

195195
let hook = Arc::new(DummyUtdHook::default());
196196
let client = test_client_builder(None).build().await.unwrap();
197-
let utd_hook =
198-
Arc::new(UtdHookManager::new(hook.clone(), client).with_max_delay(Duration::from_secs(1)));
197+
let utd_hook = Arc::new(
198+
UtdHookManager::new(hook.clone(), client).with_max_delay(Duration::from_millis(500)),
199+
);
199200

200201
let timeline = TestTimelineBuilder::new().unable_to_decrypt_hook(utd_hook.clone()).build();
201202

@@ -229,6 +230,11 @@ async fn test_false_positive_late_decryption_regression() {
229230
let own_user_id = user_id!("@example:morheus.localhost");
230231
let olm_machine = OlmMachine::new(own_user_id, "SomeDeviceId".into()).await;
231232

233+
sleep(Duration::from_millis(200)).await;
234+
235+
// Simulate a retry decryption.
236+
// Due to the regression this was marking the event as successfully decrypted on
237+
// retry
232238
timeline
233239
.controller
234240
.retry_event_decryption_test(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use ruma::{
3636
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, UserId,
3737
};
3838
use tokio::sync::{Mutex as AsyncMutex, MutexGuard};
39-
use tracing::error;
39+
use tracing::{error, trace};
4040

4141
/// A generic interface which methods get called whenever we observe a
4242
/// unable-to-decrypt (UTD) event.
@@ -234,6 +234,7 @@ impl UtdHookManager {
234234
event_timestamp: MilliSecondsSinceUnixEpoch,
235235
sender_user_id: &UserId,
236236
) {
237+
trace!(%event_id, "UtdHookManager: Observed UTD");
237238
// Hold the lock on `reported_utds` throughout, to avoid races with other
238239
// threads.
239240
let mut reported_utds_lock = self.reported_utds.lock().await;
@@ -331,6 +332,7 @@ impl UtdHookManager {
331332
/// Note: if this is called for an event that was never marked as a UTD
332333
/// before, it has no effect.
333334
pub(crate) async fn on_late_decrypt(&self, event_id: &EventId) {
335+
trace!(%event_id, "UtdHookManager: On late decrypt");
334336
// Hold the lock on `reported_utds` throughout, to avoid races with other
335337
// threads.
336338
let mut reported_utds_lock = self.reported_utds.lock().await;
@@ -339,6 +341,7 @@ impl UtdHookManager {
339341
// a pending UTD. If so, remove the event from the pending list —
340342
// doing so will cause the reporting task to no-op if it runs.
341343
let Some(pending_utd_report) = self.pending_delayed.lock().unwrap().remove(event_id) else {
344+
trace!(%event_id, "UtdHookManager: received a late decrypt report for an unknown utd");
342345
return;
343346
};
344347

0 commit comments

Comments
 (0)