threadpool: add panic_handler (#1052)

This commit is contained in:
Ryan Dahl
2019-04-21 16:26:09 -07:00
committed by Carl Lerche
parent 712ca84033
commit fea1f780bc
4 changed files with 55 additions and 0 deletions
+17
View File
@@ -399,6 +399,23 @@ fn panic_in_task() {
pool.shutdown_on_idle().wait().unwrap();
}
#[test]
fn count_panics() {
let counter = Arc::new(AtomicUsize::new(0));
let counter_ = counter.clone();
let pool = tokio_threadpool::Builder::new()
.panic_handler(move |_err| {
// We caught a panic.
counter_.fetch_add(1, Relaxed);
})
.build();
// Spawn a future that will panic.
pool.spawn(lazy(|| -> Result<(), ()> { panic!() }));
pool.shutdown_on_idle().wait().unwrap();
let counter = counter.load(Relaxed);
assert_eq!(counter, 1);
}
#[test]
fn multi_threadpool() {
use futures::sync::oneshot;