@@ -182,6 +182,7 @@ impl<T> EventCacheStoreLockPoisonError<T> {
182
182
}
183
183
}
184
184
185
+ #[ cfg( not( tarpaulin_include) ) ]
185
186
impl < T > fmt:: Debug for EventCacheStoreLockPoisonError < T > {
186
187
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
187
188
f. debug_struct ( "EventCacheStoreLockPoisonError" ) . finish_non_exhaustive ( )
@@ -194,11 +195,7 @@ impl<T> fmt::Display for EventCacheStoreLockPoisonError<T> {
194
195
}
195
196
}
196
197
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 > { }
202
199
203
200
/// Event cache store specific error type.
204
201
#[ derive( Debug , thiserror:: Error ) ]
@@ -312,14 +309,15 @@ impl BackingStore for LockableEventCacheStore {
312
309
313
310
#[ cfg( all( test, not( target_arch = "wasm32" ) ) ) ] // because time is a thing
314
311
mod tests {
315
- use std:: { sync:: Arc , time:: Duration } ;
312
+ use std:: { error :: Error , fmt , sync:: Arc , time:: Duration } ;
316
313
314
+ use assert_matches:: assert_matches;
317
315
use matrix_sdk_common:: store_locks:: MAX_BACKOFF_MS ;
318
316
use matrix_sdk_test:: async_test;
319
317
use ruma:: user_id;
320
318
use tokio:: time:: sleep;
321
319
322
- use super :: MemoryStore ;
320
+ use super :: { EventCacheStoreError , EventCacheStoreLockPoisonError , MemoryStore } ;
323
321
use crate :: { store:: StoreConfig , test_utils:: logged_in_base_client_with_store_config} ;
324
322
325
323
#[ async_test]
@@ -408,5 +406,49 @@ mod tests {
408
406
assert ! ( guard. is_ok( ) ) ; // lock has been acquired
409
407
assert ! ( guard. unwrap( ) . is_ok( ) ) ; // lock is not poisoned
410
408
}
409
+
410
+ // For the sake of improving test coverage.
411
+ // Client B cannot take the lock because A holds it.
412
+ {
413
+ // `lock` is not okay.
414
+ let guard = event_cache_store_lock_b. lock ( ) . await ;
415
+
416
+ assert ! ( guard. is_err( ) ) ; // lock has not been acquired
417
+ }
418
+ }
419
+
420
+ #[ test]
421
+ fn test_poison_error ( ) {
422
+ let error = EventCacheStoreLockPoisonError ( 42 ) ;
423
+
424
+ fn error_to_string < E > ( error : E ) -> String
425
+ where
426
+ E : Error ,
427
+ {
428
+ error. to_string ( )
429
+ }
430
+
431
+ assert_eq ! (
432
+ error_to_string( error) ,
433
+ "Poisoned lock: lock has been acquired from another process" . to_owned( ) ,
434
+ ) ;
435
+ }
436
+
437
+ #[ test]
438
+ fn test_backend_error ( ) {
439
+ #[ derive( Debug ) ]
440
+ struct Foo ;
441
+
442
+ impl fmt:: Display for Foo {
443
+ fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
444
+ formatter. debug_struct ( "Foo" ) . finish ( )
445
+ }
446
+ }
447
+
448
+ impl Error for Foo { }
449
+
450
+ let error = EventCacheStoreError :: backend ( Foo ) ;
451
+
452
+ assert_matches ! ( error, EventCacheStoreError :: Backend ( _) ) ;
411
453
}
412
454
}
0 commit comments