1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-06-27 00:27:43 +02:00

prevent spawn_fn panic bubbling (#255)

This commit is contained in:
Rob Ede
2021-01-29 14:16:10 +00:00
committed by GitHub
parent 6b86b5efc5
commit 2924419905
4 changed files with 51 additions and 61 deletions

View File

@ -1,4 +1,5 @@
use std::{
sync::mpsc::sync_channel,
thread,
time::{Duration, Instant},
};
@ -107,13 +108,29 @@ fn wait_for_spawns() {
}
#[test]
#[should_panic]
fn worker_drop_panic_fn() {
fn worker_spawn_fn_runs() {
let _ = System::new("test-system");
let (tx, rx) = sync_channel::<u32>(1);
let mut worker = Worker::new();
worker.spawn_fn(move || tx.send(42).unwrap());
let num = rx.recv().unwrap();
assert_eq!(num, 42);
worker.stop();
worker.join().unwrap();
}
#[test]
fn worker_drop_no_panic_fn() {
let _ = System::new("test-system");
let mut worker = Worker::new();
worker.spawn_fn(|| panic!("test"));
worker.stop();
worker.join().unwrap();
}
@ -158,3 +175,15 @@ fn worker_item_storage() {
worker.stop();
worker.join().unwrap();
}
#[test]
fn system_name_cow_str() {
let _ = System::new("test-system");
System::current().stop();
}
#[test]
fn system_name_cow_string() {
let _ = System::new("test-system".to_owned());
System::current().stop();
}