Skip to content

Commit 6639c3b

Browse files
f have stop() join on the thread
1 parent f9f3548 commit 6639c3b

File tree

1 file changed

+8
-11
lines changed
  • background-processor/src

1 file changed

+8
-11
lines changed

background-processor/src/lib.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ impl BackgroundProcessor {
103103
}
104104

105105
/// 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()
108109
}
109110
}
110111

@@ -277,8 +278,6 @@ mod tests {
277278
break
278279
}
279280
}
280-
processor.stop();
281-
processor.thread_handle.join().unwrap();
282281
}
283282

284283
#[test]
@@ -309,7 +308,7 @@ mod tests {
309308
let bg_processor = BackgroundProcessor::start(persist_manager, nodes[0].node.clone(), nodes[0].logger.clone());
310309
open_channel!(nodes[0], nodes[1], 100000);
311310

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");
313312
}
314313

315314
#[test]
@@ -321,12 +320,10 @@ mod tests {
321320
let bg_processor = BackgroundProcessor::start(callback, nodes[0].node.clone(), nodes[0].logger.clone());
322321

323322
// 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");
330327
}
331328
}
332329
}

0 commit comments

Comments
 (0)