mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
process: Share init in tests
This commit is contained in:
+3
-36
@@ -1,50 +1,17 @@
|
||||
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;
|
||||
use std::process::Command;
|
||||
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_process::CommandExt;
|
||||
|
||||
static INIT: Once = ONCE_INIT;
|
||||
|
||||
fn init() {
|
||||
INIT.call_once(|| {
|
||||
let (tx, rx) = channel();
|
||||
thread::spawn(move || {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let mut cmd = exit();
|
||||
let mut child = cmd.spawn_async(&lp.handle()).unwrap();
|
||||
drop(child.kill());
|
||||
lp.run(child).unwrap();
|
||||
tx.send(()).unwrap();
|
||||
drop(lp.run(futures::empty::<(), ()>()));
|
||||
});
|
||||
rx.recv().unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
fn exit() -> Command {
|
||||
let mut me = env::current_exe().unwrap();
|
||||
me.pop();
|
||||
if me.ends_with("deps") {
|
||||
me.pop();
|
||||
}
|
||||
me.push("exit");
|
||||
Command::new(me)
|
||||
}
|
||||
mod support;
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
init();
|
||||
support::init();
|
||||
|
||||
let mut lp = Core::new().unwrap();
|
||||
let mut cmd = exit();
|
||||
let mut cmd = support::cmd("exit");
|
||||
cmd.arg("2");
|
||||
let mut child = cmd.spawn_async(&lp.handle()).unwrap();
|
||||
let id = child.id();
|
||||
|
||||
Reference in New Issue
Block a user