Skip to content

Commit cd4c12e

Browse files
committed
test(base): Improve test coverage.
1 parent 5073cd1 commit cd4c12e

File tree

1 file changed

+40
-7
lines changed
  • crates/matrix-sdk-base/src/event_cache/store

1 file changed

+40
-7
lines changed

crates/matrix-sdk-base/src/event_cache/store/mod.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ impl<T> EventCacheStoreLockPoisonError<T> {
182182
}
183183
}
184184

185+
#[cfg(not(tarpaulin_include))]
185186
impl<T> fmt::Debug for EventCacheStoreLockPoisonError<T> {
186187
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
187188
f.debug_struct("EventCacheStoreLockPoisonError").finish_non_exhaustive()
@@ -194,11 +195,7 @@ impl<T> fmt::Display for EventCacheStoreLockPoisonError<T> {
194195
}
195196
}
196197

197-
impl<T> Error for EventCacheStoreLockPoisonError<T> {
198-
fn description(&self) -> &str {
199-
"Poisoned lock: lock has been acquired from another process"
200-
}
201-
}
198+
impl<T> Error for EventCacheStoreLockPoisonError<T> {}
202199

203200
/// Event cache store specific error type.
204201
#[derive(Debug, thiserror::Error)]
@@ -312,14 +309,15 @@ impl BackingStore for LockableEventCacheStore {
312309

313310
#[cfg(all(test, not(target_arch = "wasm32")))] // because time is a thing
314311
mod tests {
315-
use std::{sync::Arc, time::Duration};
312+
use std::{error::Error, fmt, sync::Arc, time::Duration};
316313

314+
use assert_matches::assert_matches;
317315
use matrix_sdk_common::store_locks::MAX_BACKOFF_MS;
318316
use matrix_sdk_test::async_test;
319317
use ruma::user_id;
320318
use tokio::time::sleep;
321319

322-
use super::MemoryStore;
320+
use super::{EventCacheStoreError, EventCacheStoreLockPoisonError, MemoryStore};
323321
use crate::{store::StoreConfig, test_utils::logged_in_base_client_with_store_config};
324322

325323
#[async_test]
@@ -409,4 +407,39 @@ mod tests {
409407
assert!(guard.unwrap().is_ok()); // lock is not poisoned
410408
}
411409
}
410+
411+
#[test]
412+
fn test_poison_error() {
413+
let error = EventCacheStoreLockPoisonError(42);
414+
415+
fn error_to_string<E>(error: E) -> String
416+
where
417+
E: Error,
418+
{
419+
error.to_string()
420+
}
421+
422+
assert_eq!(
423+
error_to_string(error),
424+
"Poisoned lock: lock has been acquired from another process".to_owned(),
425+
);
426+
}
427+
428+
#[test]
429+
fn test_backend_error() {
430+
#[derive(Debug)]
431+
struct Foo;
432+
433+
impl fmt::Display for Foo {
434+
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
435+
formatter.debug_struct("Foo").finish()
436+
}
437+
}
438+
439+
impl Error for Foo {}
440+
441+
let error = EventCacheStoreError::backend(Foo);
442+
443+
assert_matches!(error, EventCacheStoreError::Backend(_));
444+
}
412445
}

0 commit comments

Comments
 (0)