Files
tokio/tests/smoke.rs
T

56 lines
1.3 KiB
Rust
Raw Normal View History

2016-09-07 00:13:11 -07:00
extern crate futures;
extern crate tokio_core;
extern crate tokio_process;
use std::env;
use std::sync::mpsc::channel;
use std::sync::{Once, ONCE_INIT};
use std::thread;
2016-09-07 22:15:13 -07:00
use tokio_core::reactor::{Core, Handle};
2016-09-07 00:13:11 -07:00
use tokio_process::Command;
static INIT: Once = ONCE_INIT;
fn init() {
INIT.call_once(|| {
let (tx, rx) = channel();
thread::spawn(move || {
2016-09-07 22:15:13 -07:00
let mut lp = Core::new().unwrap();
2016-09-07 00:13:11 -07:00
let cmd = exit(&lp.handle());
let mut child = lp.run(cmd.spawn()).unwrap();
drop(child.kill());
lp.run(child).unwrap();
tx.send(()).unwrap();
drop(lp.run(futures::empty::<(), ()>()));
});
rx.recv().unwrap();
});
}
2016-09-07 22:15:13 -07:00
fn exit(handle: &Handle) -> Command {
2016-09-07 00:13:11 -07:00
let mut me = env::current_exe().unwrap();
me.pop();
2016-11-19 10:03:43 -08:00
if me.ends_with("deps") {
me.pop();
}
2016-09-07 00:13:11 -07:00
me.push("exit");
Command::new(me, handle)
}
#[test]
fn simple() {
init();
2016-09-07 22:15:13 -07:00
let mut lp = Core::new().unwrap();
2016-09-07 00:13:11 -07:00
let mut cmd = exit(&lp.handle());
cmd.arg("2");
let mut child = lp.run(cmd.spawn()).unwrap();
let id = child.id();
assert!(id > 0);
let status = lp.run(&mut child).unwrap();
assert_eq!(status.code(), Some(2));
assert_eq!(child.id(), id);
2016-09-07 12:59:46 -07:00
drop(child.kill());
2016-09-07 00:13:11 -07:00
}