rust/src/test/run-pass/pipe-select.rs

102 lines
2.0 KiB
Rust
Raw Normal View History

2012-07-06 01:14:27 -05:00
// xfail-pretty
// xfail-win32
2012-07-06 01:14:27 -05:00
extern mod std;
2012-09-05 14:32:05 -05:00
use std::timer::sleep;
use std::uv;
2012-09-05 14:32:05 -05:00
use pipes::{recv, select};
proto! oneshot (
2012-07-06 01:14:27 -05:00
waiting:send {
signal -> !
}
)
proto! stream (
stream:send<T:Send> {
2012-07-06 01:14:27 -05:00
send(T) -> stream<T>
}
)
fn main() {
use oneshot::client::*;
use stream::client::*;
let iotask = uv::global_loop::get();
let c = pipes::spawn_service(stream::init, |p| {
2012-08-22 19:24:52 -05:00
error!("waiting for pipes");
let stream::send(x, p) = recv(p);
2012-08-22 19:24:52 -05:00
error!("got pipes");
let (left, right) : (oneshot::server::waiting,
oneshot::server::waiting)
= x;
2012-08-22 19:24:52 -05:00
error!("selecting");
let (i, _, _) = select(~[left, right]);
2012-08-22 19:24:52 -05:00
error!("selected");
assert i == 0;
2012-08-22 19:24:52 -05:00
error!("waiting for pipes");
let stream::send(x, _) = recv(p);
2012-08-22 19:24:52 -05:00
error!("got pipes");
let (left, right) : (oneshot::server::waiting,
oneshot::server::waiting)
= x;
2012-08-22 19:24:52 -05:00
error!("selecting");
let (i, m, _) = select(~[left, right]);
2012-08-22 19:24:52 -05:00
error!("selected %?", i);
if m.is_some() {
assert i == 1;
}
});
let (c1, p1) = oneshot::init();
2012-07-10 18:46:16 -05:00
let (_c2, p2) = oneshot::init();
let c = send(c, (p1, p2));
sleep(iotask, 100);
signal(c1);
2012-07-10 18:46:16 -05:00
let (_c1, p1) = oneshot::init();
let (c2, p2) = oneshot::init();
send(c, (p1, p2));
sleep(iotask, 100);
signal(c2);
2012-07-09 15:53:55 -05:00
test_select2();
}
fn test_select2() {
let (ac, ap) = stream::init();
let (bc, bp) = stream::init();
stream::client::send(ac, 42);
2012-08-06 14:34:08 -05:00
match pipes::select2(ap, bp) {
2012-08-14 18:54:13 -05:00
either::Left(*) => { }
either::Right(*) => { fail }
2012-07-09 15:53:55 -05:00
}
stream::client::send(bc, ~"abc");
2012-07-09 15:53:55 -05:00
2012-08-22 19:24:52 -05:00
error!("done with first select2");
2012-07-09 15:53:55 -05:00
let (ac, ap) = stream::init();
let (bc, bp) = stream::init();
stream::client::send(bc, ~"abc");
2012-07-09 15:53:55 -05:00
2012-08-06 14:34:08 -05:00
match pipes::select2(ap, bp) {
2012-08-14 18:54:13 -05:00
either::Left(*) => { fail }
either::Right(*) => { }
2012-07-09 15:53:55 -05:00
}
stream::client::send(ac, 42);
}