@@ -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]
@@ -409,4 +407,39 @@ mod tests {
409
407
assert ! ( guard. unwrap( ) . is_ok( ) ) ; // lock is not poisoned
410
408
}
411
409
}
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
+ }
412
445
}
0 commit comments