@@ -103,8 +103,9 @@ impl BackgroundProcessor {
103
103
}
104
104
105
105
/// Stop `BackgroundProcessor`'s thread.
106
- pub fn stop ( & self ) {
107
- self . stop_thread . store ( true , Ordering :: Release )
106
+ pub fn stop ( self ) -> Result < ( ) , std:: io:: Error > {
107
+ self . stop_thread . store ( true , Ordering :: Release ) ;
108
+ self . thread_handle . join ( ) . unwrap ( )
108
109
}
109
110
}
110
111
@@ -277,8 +278,6 @@ mod tests {
277
278
break
278
279
}
279
280
}
280
- processor. stop ( ) ;
281
- processor. thread_handle . join ( ) . unwrap ( ) ;
282
281
}
283
282
284
283
#[ test]
@@ -309,7 +308,7 @@ mod tests {
309
308
let bg_processor = BackgroundProcessor :: start ( persist_manager, nodes[ 0 ] . node . clone ( ) , nodes[ 0 ] . logger . clone ( ) ) ;
310
309
open_channel ! ( nodes[ 0 ] , nodes[ 1 ] , 100000 ) ;
311
310
312
- let _ = bg_processor. thread_handle . join ( ) . expect_err ( "Errored persisting manager: test" ) ;
311
+ let _ = bg_processor. thread_handle . join ( ) . unwrap ( ) . expect_err ( "Errored persisting manager: test" ) ;
313
312
}
314
313
315
314
#[ test]
@@ -321,12 +320,10 @@ mod tests {
321
320
let bg_processor = BackgroundProcessor :: start ( callback, nodes[ 0 ] . node . clone ( ) , nodes[ 0 ] . logger . clone ( ) ) ;
322
321
323
322
// Stop the background processor and check that it terminated.
324
- bg_processor. stop ( ) ;
325
- loop {
326
- let log_entries = nodes[ 0 ] . logger . lines . lock ( ) . unwrap ( ) ;
327
- if log_entries. get ( & ( "background_processor" . to_string ( ) , "Terminating background processor." . to_string ( ) ) ) . is_some ( ) {
328
- break
329
- }
323
+ assert ! ( bg_processor. stop( ) . is_ok( ) ) ;
324
+ let log_entries = nodes[ 0 ] . logger . lines . lock ( ) . unwrap ( ) ;
325
+ if !log_entries. get ( & ( "background_processor" . to_string ( ) , "Terminating background processor." . to_string ( ) ) ) . is_some ( ) {
326
+ panic ! ( "Expected to log on stopping thread" ) ;
330
327
}
331
328
}
332
329
}
0 commit comments