Skip to content

Commit

Permalink
[WIP] Re-add disabled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jul 2, 2019
1 parent 90f9630 commit 0ac6339
Show file tree
Hide file tree
Showing 11 changed files with 1,154 additions and 1,083 deletions.
262 changes: 157 additions & 105 deletions futures/tests_disabled/all.rs → futures/tests/all.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
use futures::future;
use futures::executor::block_on;
use futures::channel::oneshot::{self, Canceled};
use futures::executor::block_on;
use futures::future::{self, Either};
use futures_test::task::{noop_context, panic_context};
use std::sync::mpsc::{channel, TryRecvError};

mod support;
use support::*;

fn unselect<T, E, A, B>(r: Result<Either<(T, B), (T, A)>, Either<(E, B), (E, A)>>) -> Result<T, E> {
match r {
Ok(Either::Left((t, _))) |
Ok(Either::Right((t, _))) => Ok(t),
Err(Either::Left((e, _))) |
Err(Either::Right((e, _))) => Err(e),
Ok(Either::Left((t, _))) | Ok(Either::Right((t, _))) => Ok(t),
Err(Either::Left((e, _))) | Err(Either::Right((e, _))) => Err(e),
}
}

#[test]
fn result_smoke() {
fn is_future_v<A, B, C>(_: C)
where A: Send + 'static,
B: Send + 'static,
C: Future<Item=A, Error=B>
{}
where
A: Send + 'static,
B: Send + 'static,
C: Future<Item = A, Error = B>,
{
}

is_future_v::<i32, u32, _>(f_ok(1).map(|a| a + 1));
is_future_v::<i32, u32, _>(f_ok(1).map_err(|a| a + 1));
Expand Down Expand Up @@ -64,7 +62,9 @@ fn result_smoke() {

#[test]
fn test_empty() {
fn empty() -> Empty<i32, u32> { future::empty() }
fn empty() -> Empty<i32, u32> {
future::empty()
}

assert_empty(|| empty());
assert_empty(|| empty().select(empty()));
Expand Down Expand Up @@ -105,16 +105,22 @@ fn flatten() {

#[test]
fn smoke_oneshot() {
assert_done(|| {
let (c, p) = oneshot::channel();
c.send(1).unwrap();
p
}, Ok(1));
assert_done(|| {
let (c, p) = oneshot::channel::<i32>();
drop(c);
p
}, Err(Canceled));
assert_done(
|| {
let (c, p) = oneshot::channel();
c.send(1).unwrap();
p
},
Ok(1),
);
assert_done(
|| {
let (c, p) = oneshot::channel::<i32>();
drop(c);
p
},
Err(Canceled),
);
let mut completes = Vec::new();
assert_empty(|| {
let (a, b) = oneshot::channel::<i32>();
Expand All @@ -124,77 +130,99 @@ fn smoke_oneshot() {

let (c, mut p) = oneshot::channel::<i32>();
drop(c);
let res = panic_waker_lw(|lw| p.poll(lw));
let res = p.poll(&mut panic_context());
assert!(res.is_err());
let (c, p) = oneshot::channel::<i32>();
drop(c);
let (tx, rx) = channel();
p.then(move |_| {
tx.send(())
}).forget();
p.then(move |_| tx.send(())).forget();
rx.recv().unwrap();
}

#[test]
fn select_cancels() {
let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |b| { btx.send(b).unwrap(); b });
let d = d.map(move |d| { dtx.send(d).unwrap(); d });
let b = b.map(move |b| {
btx.send(b).unwrap();
b
});
let d = d.map(move |d| {
dtx.send(d).unwrap();
d
});

let mut f = b.select(d).then(unselect);
// assert!(f.poll(&mut Task::new()).is_pending());
assert!(brx.try_recv().is_err());
assert!(drx.try_recv().is_err());
a.send(1).unwrap();
noop_waker_lw(|lw| {
let res = f.poll(lw);
assert!(res.ok().unwrap().is_ready());
assert_eq!(brx.recv().unwrap(), 1);
drop(c);
assert!(drx.recv().is_err());
let cx = &mut noop_context();
let res = f.poll(cx);
assert!(res.ok().unwrap().is_ready());
assert_eq!(brx.recv().unwrap(), 1);
drop(c);
assert!(drx.recv().is_err());

let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, _brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |b| { btx.send(b).unwrap(); b });
let d = d.map(move |d| { dtx.send(d).unwrap(); d });
let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, _brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |b| {
btx.send(b).unwrap();
b
});
let d = d.map(move |d| {
dtx.send(d).unwrap();
d
});

let mut f = b.select(d).then(unselect);
assert!(f.poll(lw).ok().unwrap().is_pending());
assert!(f.poll(lw).ok().unwrap().is_pending());
a.send(1).unwrap();
assert!(f.poll(lw).ok().unwrap().is_ready());
drop((c, f));
assert!(drx.recv().is_err());
})
let mut f = b.select(d).then(unselect);
assert!(f.poll(cx).ok().unwrap().is_pending());
assert!(f.poll(cx).ok().unwrap().is_pending());
a.send(1).unwrap();
assert!(f.poll(cx).ok().unwrap().is_ready());
drop((c, f));
assert!(drx.recv().is_err());
}

#[test]
fn join_cancels() {
let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, _brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |b| { btx.send(b).unwrap(); b });
let d = d.map(move |d| { dtx.send(d).unwrap(); d });
let b = b.map(move |b| {
btx.send(b).unwrap();
b
});
let d = d.map(move |d| {
dtx.send(d).unwrap();
d
});

let mut f = b.join(d);
drop(a);
let res = panic_waker_lw(|lw| f.poll(lw));
let res = f.poll(&mut panic_context());
assert!(res.is_err());
drop(c);
assert!(drx.recv().is_err());

let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, _brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |b| { btx.send(b).unwrap(); b });
let d = d.map(move |d| { dtx.send(d).unwrap(); d });
let b = b.map(move |b| {
btx.send(b).unwrap();
b
});
let d = d.map(move |d| {
dtx.send(d).unwrap();
d
});

let (tx, rx) = channel();
let f = b.join(d);
f.then(move |_| {
tx.send(()).unwrap();
let res: Result<(), ()> = Ok(());
res
}).forget();
})
.forget();
assert!(rx.try_recv().is_err());
drop(a);
rx.recv().unwrap();
Expand All @@ -206,59 +234,61 @@ fn join_cancels() {
fn join_incomplete() {
let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
noop_waker_lw(|lw| {
let mut f = ok(1).join(b).map(move |r| tx.send(r).unwrap());
assert!(f.poll(lw).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
a.send(2).unwrap();
assert!(f.poll(lw).ok().unwrap().is_ready());
assert_eq!(rx.recv().unwrap(), (1, 2));
let cx = &mut noop_context();
let mut f = ok(1).join(b).map(move |r| tx.send(r).unwrap());
assert!(f.poll(cx).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
a.send(2).unwrap();
assert!(f.poll(cx).ok().unwrap().is_ready());
assert_eq!(rx.recv().unwrap(), (1, 2));

let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = b.join(Ok(2)).map(move |r| tx.send(r).unwrap());
assert!(f.poll(lw).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
a.send(1).unwrap();
assert!(f.poll(lw).ok().unwrap().is_ready());
assert_eq!(rx.recv().unwrap(), (1, 2));
let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = b.join(Ok(2)).map(move |r| tx.send(r).unwrap());
assert!(f.poll(cx).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
a.send(1).unwrap();
assert!(f.poll(cx).ok().unwrap().is_ready());
assert_eq!(rx.recv().unwrap(), (1, 2));

let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = ok(1).join(b).map_err(move |_r| tx.send(2).unwrap());
assert!(f.poll(lw).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
drop(a);
assert!(f.poll(lw).is_err());
assert_eq!(rx.recv().unwrap(), 2);
let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = ok(1).join(b).map_err(move |_r| tx.send(2).unwrap());
assert!(f.poll(cx).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
drop(a);
assert!(f.poll(cx).is_err());
assert_eq!(rx.recv().unwrap(), 2);

let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = b.join(Ok(2)).map_err(move |_r| tx.send(1).unwrap());
assert!(f.poll(lw).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
drop(a);
assert!(f.poll(lw).is_err());
assert_eq!(rx.recv().unwrap(), 1);
})
let (a, b) = oneshot::channel::<i32>();
let (tx, rx) = channel();
let mut f = b.join(Ok(2)).map_err(move |_r| tx.send(1).unwrap());
assert!(f.poll(cx).ok().unwrap().is_pending());
assert!(rx.try_recv().is_err());
drop(a);
assert!(f.poll(cx).is_err());
assert_eq!(rx.recv().unwrap(), 1);
}


#[test]
fn select2() {
fn select() {
assert_done(|| f_ok(2).select(empty()).then(unselect), Ok(2));
assert_done(|| empty().select(f_ok(2)).then(unselect), Ok(2));
assert_done(|| f_err(2).select(empty()).then(unselect), Err(2));
assert_done(|| empty().select(f_err(2)).then(unselect), Err(2));

assert_done(|| {
f_ok(1).select(f_ok(2))
.map_err(|_| 0)
.and_then(|either_tup| {
let (a, b) = either_tup.into_inner();
b.map(move |b| a + b)
})
}, Ok(3));
assert_done(
|| {
f_ok(1)
.select(f_ok(2))
.map_err(|_| 0)
.and_then(|either_tup| {
let (a, b) = either_tup.into_inner();
b.map(move |b| a + b)
})
},
Ok(3),
);

// Finish one half of a select and then fail the second, ensuring that we
// get the notification of the second one.
Expand All @@ -282,7 +312,8 @@ fn select2() {
let ((a, b), (c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let f = b.select(d);
let (tx, rx) = channel();
f.map_err(move |r| tx.send((1, r.into_inner().1)).unwrap()).forget();
f.map_err(move |r| tx.send((1, r.into_inner().1)).unwrap())
.forget();
drop(c);
let (val, next) = rx.recv().unwrap();
assert_eq!(val, 1);
Expand All @@ -297,8 +328,14 @@ fn select2() {
{
let ((_a, b), (_c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |v| { btx.send(v).unwrap(); v });
let d = d.map(move |v| { dtx.send(v).unwrap(); v });
let b = b.map(move |v| {
btx.send(v).unwrap();
v
});
let d = d.map(move |v| {
dtx.send(v).unwrap();
v
});
let f = b.select(d);
drop(f);
assert!(drx.recv().is_err());
Expand All @@ -309,10 +346,16 @@ fn select2() {
{
let ((_a, b), (_c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |v| { btx.send(v).unwrap(); v });
let d = d.map(move |v| { dtx.send(v).unwrap(); v });
let b = b.map(move |v| {
btx.send(v).unwrap();
v
});
let d = d.map(move |v| {
dtx.send(v).unwrap();
v
});
let mut f = b.select(d);
let _res = noop_waker_lw(|lw| f.poll(lw));
let _res = f.poll(&mut noop_context());
drop(f);
assert!(drx.recv().is_err());
assert!(brx.recv().is_err());
Expand All @@ -322,8 +365,14 @@ fn select2() {
{
let ((a, b), (_c, d)) = (oneshot::channel::<i32>(), oneshot::channel::<i32>());
let ((btx, brx), (dtx, drx)) = (channel(), channel());
let b = b.map(move |v| { btx.send(v).unwrap(); v });
let d = d.map(move |v| { dtx.send(v).unwrap(); v });
let b = b.map(move |v| {
btx.send(v).unwrap();
v
});
let d = d.map(move |v| {
dtx.send(v).unwrap();
v
});
let (tx, rx) = channel();
b.select(d).map(move |_| tx.send(()).unwrap()).forget();
drop(a);
Expand All @@ -347,5 +396,8 @@ fn select2() {
#[test]
fn option() {
assert_eq!(Ok(Some(())), block_on(Some(ok::<(), ()>(())).into_future()));
assert_eq!(Ok::<_, ()>(None::<()>), block_on(None::<FutureResult<(), ()>>.into_future()));
assert_eq!(
Ok::<_, ()>(None::<()>),
block_on(None::<FutureResult<(), ()>>.into_future())
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::SinkExt;
use futures::sink::SinkExt;
use futures::executor::{block_on, block_on_stream};
use futures::stream::StreamExt;
use futures::channel::oneshot;
Expand Down
Loading

0 comments on commit 0ac6339

Please sign in to comment.