mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
signal: panic
This commit is contained in:
committed by
Carl Lerche
parent
1fdff707b8
commit
f759e4d70f
+30
-7
@@ -2,6 +2,7 @@
|
||||
|
||||
extern crate futures;
|
||||
extern crate libc;
|
||||
extern crate tokio;
|
||||
extern crate tokio_core;
|
||||
extern crate tokio_signal;
|
||||
|
||||
@@ -10,7 +11,7 @@ use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::stream::Stream;
|
||||
use futures::Future;
|
||||
use futures::{future, Future, IntoFuture};
|
||||
use tokio_core::reactor::{Core, Timeout};
|
||||
use tokio_signal::unix::Signal;
|
||||
|
||||
@@ -18,19 +19,38 @@ use tokio_signal::unix::Signal;
|
||||
fn simple() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle)).unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
lp.run(signal.into_future()).ok().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tokio_simple() {
|
||||
tokio::run(
|
||||
future::lazy(|| {
|
||||
Signal::new(libc::SIGUSR1, &tokio::reactor::Handle::default())
|
||||
.into_future()
|
||||
.and_then(|signal| {
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
signal.into_future().map(|_| ()).map_err(|(err, _)| err)
|
||||
})
|
||||
}).map_err(|err| panic!("{}", err)),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notify_both() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal1 = lp.run(Signal::new(libc::SIGUSR2, &handle)).unwrap();
|
||||
let signal2 = lp.run(Signal::new(libc::SIGUSR2, &handle)).unwrap();
|
||||
let signal1 = lp.run(Signal::new(libc::SIGUSR2, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal2 = lp.run(Signal::new(libc::SIGUSR2, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR2), 0);
|
||||
}
|
||||
@@ -43,7 +63,8 @@ fn notify_both() {
|
||||
fn drop_then_get_a_signal() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle)).unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
drop(signal);
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
@@ -56,7 +77,8 @@ fn drop_then_get_a_signal() {
|
||||
fn twice() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle)).unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
@@ -81,7 +103,8 @@ fn multi_loop() {
|
||||
thread::spawn(move || {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGHUP, &handle)).unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGHUP, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
sender.send(()).unwrap();
|
||||
lp.run(signal.into_future()).ok().unwrap();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user