mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-30 00:00:16 +02:00
threadpool: add panic_handler (#1052)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user