mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
chore: clippy + review feedback
This commit is contained in:
@@ -46,15 +46,19 @@ use tracing::{debug, trace};
|
||||
pub struct EncryptionSyncPermit(());
|
||||
|
||||
impl EncryptionSyncPermit {
|
||||
/// Create a new [`EncryptionSyncPermit`].
|
||||
///
|
||||
/// Note: in general, you'd want to get such a permit from a [`SyncService`]
|
||||
/// instead of creating it yourself.
|
||||
pub fn new() -> Self {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(())
|
||||
}
|
||||
}
|
||||
|
||||
impl EncryptionSyncPermit {
|
||||
/// Test-only.
|
||||
#[doc(hidden)]
|
||||
pub fn new_for_testing() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Should the `EncryptionSync` make use of locking?
|
||||
pub enum WithLocking {
|
||||
Yes,
|
||||
|
||||
@@ -192,10 +192,18 @@ impl NotificationClient {
|
||||
// means we were racing against the encryption sync. Wait a bit, attempt to
|
||||
// decrypt, and carry on.
|
||||
|
||||
let mut wait = 200; // we get to wait 7 times that number at most.
|
||||
// We repeat the sleep 3 times at most, each iteration we
|
||||
// double the amount of time waited, so overall we may wait up to 7 times this
|
||||
// amount.
|
||||
let mut wait = 200;
|
||||
|
||||
for _ in 0..3 {
|
||||
tracing::debug!("Sync running in background while getting a notification; waiting for decryption…");
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(wait)).await; // heuristics~~~
|
||||
//
|
||||
let new_event = room.decrypt_event(raw_event.cast_ref()).await?;
|
||||
|
||||
if !is_event_encrypted(
|
||||
new_event
|
||||
.event
|
||||
@@ -203,12 +211,17 @@ impl NotificationClient {
|
||||
.map_err(|_| Error::InvalidRumaEvent)?
|
||||
.event_type(),
|
||||
) {
|
||||
tracing::debug!("Waiting succeeded!");
|
||||
return Ok(Some(new_event));
|
||||
}
|
||||
|
||||
wait *= 2;
|
||||
}
|
||||
|
||||
// We couldn't decrypt the event after waiting a few times, abort.
|
||||
tracing::debug!(
|
||||
"Timeout waiting for the sync service to decrypt the notification event."
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
async fn test_smoke_encryption_sync_works() -> anyhow::Result<()> {
|
||||
let (client, server) = logged_in_client().await;
|
||||
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
|
||||
let sync_permit_guard = sync_permit.clone().lock_owned().await;
|
||||
let encryption_sync =
|
||||
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
|
||||
@@ -111,7 +111,6 @@ async fn test_smoke_encryption_sync_works() -> anyhow::Result<()> {
|
||||
assert!(stream.next().await.is_none());
|
||||
|
||||
// Start a new sync.
|
||||
drop(stream);
|
||||
let sync_permit_guard = sync_permit.clone().lock_owned().await;
|
||||
let stream = encryption_sync.sync(sync_permit_guard);
|
||||
pin_mut!(stream);
|
||||
@@ -198,7 +197,7 @@ async fn test_encryption_sync_one_fixed_iteration() -> anyhow::Result<()> {
|
||||
|
||||
let _guard = setup_mocking_sliding_sync_server(&server).await;
|
||||
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
|
||||
let sync_permit_guard = sync_permit.lock_owned().await;
|
||||
let encryption_sync =
|
||||
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
|
||||
@@ -230,7 +229,7 @@ async fn test_encryption_sync_two_fixed_iterations() -> anyhow::Result<()> {
|
||||
|
||||
let _guard = setup_mocking_sliding_sync_server(&server).await;
|
||||
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
|
||||
let sync_permit_guard = sync_permit.lock_owned().await;
|
||||
let encryption_sync =
|
||||
EncryptionSync::new("tests".to_owned(), client, None, WithLocking::Yes).await?;
|
||||
@@ -265,7 +264,7 @@ async fn test_encryption_sync_two_fixed_iterations() -> anyhow::Result<()> {
|
||||
async fn test_encryption_sync_always_reloads_todevice_token() -> anyhow::Result<()> {
|
||||
let (client, server) = logged_in_client().await;
|
||||
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
|
||||
let sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new_for_testing()));
|
||||
let sync_permit_guard = sync_permit.lock_owned().await;
|
||||
let encryption_sync =
|
||||
EncryptionSync::new("tests".to_owned(), client.clone(), None, WithLocking::Yes).await?;
|
||||
|
||||
Reference in New Issue
Block a user