mirror of https://github.com/fafhrd91/actix-net
describe panicking behavior in tests
This commit is contained in:
parent
03febde4da
commit
6f7508c771
|
@ -2,13 +2,12 @@
|
|||
|
||||
## Unreleased - 2021-xx-xx
|
||||
|
||||
* Remove `run_in_tokio` and `attach_to_tokio`. [#253]
|
||||
* Remove `AsyncSystemRunner`. [#253]
|
||||
* Remove `run_in_tokio`, `attach_to_tokio` and `AsyncSystemRunner`. [#253]
|
||||
* Return `JoinHandle` from `actix_rt::spawn`. [#253]
|
||||
* Remove old `Arbiter::spawn`. Implementation is now inlined into `actix_rt::spawn`. [#253]
|
||||
* Rename `Arbiter::{send => spawn}` and `Arbiter::{exec_fn => spawn_fn}`. [#253]
|
||||
* Remove `Arbiter::exec`. [#253]
|
||||
* Remove deprecated `Arbiter::local_join`. [#253]
|
||||
* Remove deprecated `Arbiter::local_join` and `Arbiter::is_running`. [#253]
|
||||
|
||||
[#253]: https://github.com/actix/actix-net/pull/253
|
||||
|
||||
|
|
|
@ -87,12 +87,6 @@ impl Arbiter {
|
|||
})
|
||||
}
|
||||
|
||||
/// Check if current arbiter is running.
|
||||
#[deprecated(note = "Thread local variables for running state of Arbiter is removed")]
|
||||
pub fn is_running() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Stop arbiter from continuing it's event loop.
|
||||
pub fn stop(&self) {
|
||||
let _ = self.sender.send(ArbiterCommand::Stop);
|
||||
|
@ -122,7 +116,7 @@ impl Arbiter {
|
|||
|
||||
// register arbiter
|
||||
let _ = System::current()
|
||||
.sys()
|
||||
.tx()
|
||||
.send(SystemCommand::RegisterArbiter(id, arb));
|
||||
|
||||
// start arbiter controller
|
||||
|
@ -131,7 +125,7 @@ impl Arbiter {
|
|||
|
||||
// deregister arbiter
|
||||
let _ = System::current()
|
||||
.sys()
|
||||
.tx()
|
||||
.send(SystemCommand::DeregisterArbiter(id));
|
||||
}
|
||||
})
|
||||
|
@ -243,6 +237,7 @@ struct ArbiterController {
|
|||
|
||||
impl Drop for ArbiterController {
|
||||
fn drop(&mut self) {
|
||||
// panics can only occur with spawn_fn calls
|
||||
if thread::panicking() {
|
||||
if System::current().stop_on_panic() {
|
||||
eprintln!("Panic in Arbiter thread, shutting down system.");
|
||||
|
|
|
@ -17,7 +17,7 @@ static SYSTEM_COUNT: AtomicUsize = AtomicUsize::new(0);
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct System {
|
||||
id: usize,
|
||||
sys: UnboundedSender<SystemCommand>,
|
||||
tx: UnboundedSender<SystemCommand>,
|
||||
arbiter: Arbiter,
|
||||
stop_on_panic: bool,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ impl System {
|
|||
stop_on_panic: bool,
|
||||
) -> Self {
|
||||
let sys = System {
|
||||
sys,
|
||||
tx: sys,
|
||||
arbiter,
|
||||
stop_on_panic,
|
||||
id: SYSTEM_COUNT.fetch_add(1, Ordering::SeqCst),
|
||||
|
@ -102,11 +102,11 @@ impl System {
|
|||
|
||||
/// Stop the system with a particular exit code.
|
||||
pub fn stop_with_code(&self, code: i32) {
|
||||
let _ = self.sys.send(SystemCommand::Exit(code));
|
||||
let _ = self.tx.send(SystemCommand::Exit(code));
|
||||
}
|
||||
|
||||
pub(crate) fn sys(&self) -> &UnboundedSender<SystemCommand> {
|
||||
&self.sys
|
||||
pub(crate) fn tx(&self) -> &UnboundedSender<SystemCommand> {
|
||||
&self.tx
|
||||
}
|
||||
|
||||
/// Return status of 'stop_on_panic' option which controls whether the System is stopped when an
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use std::time::{Duration, Instant};
|
||||
use std::{
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use actix_rt::{Arbiter, System};
|
||||
use futures_util::future::lazy;
|
||||
use tokio::task::LocalSet;
|
||||
|
||||
#[test]
|
||||
fn await_for_timer() {
|
||||
|
@ -104,3 +105,33 @@ fn wait_for_spawns() {
|
|||
|
||||
assert!(rt.block_on(handle).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn arbiter_drop_panic_fn() {
|
||||
let _ = System::new("test-system");
|
||||
|
||||
let mut arbiter = Arbiter::new();
|
||||
arbiter.spawn_fn(|| panic!("test"));
|
||||
|
||||
arbiter.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arbiter_drop_no_panic_fut() {
|
||||
use futures_util::future::lazy;
|
||||
|
||||
let _ = System::new("test-system");
|
||||
|
||||
let mut arbiter = Arbiter::new();
|
||||
arbiter.spawn(lazy(|_| panic!("test")));
|
||||
|
||||
let arb = arbiter.clone();
|
||||
let thread = thread::spawn(move || {
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
arb.stop();
|
||||
});
|
||||
|
||||
arbiter.join().unwrap();
|
||||
thread.join().unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue