Skip to content

Commit 6bb6881

Browse files
taiki-ecramertj
authored andcommitted
Re-add tests that needed future::[try_]select
1 parent a496d51 commit 6bb6881

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

futures/tests/futures_ordered.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use futures::channel::oneshot;
22
use futures::executor::{block_on, block_on_stream};
3-
use futures::future::{self, join, FutureExt};
3+
use futures::future::{self, join, Future, FutureExt, TryFutureExt};
44
use futures::stream::{StreamExt, FuturesOrdered};
55
use futures_test::task::noop_context;
6+
use std::any::Any;
67

78
#[test]
89
fn works_1() {
@@ -56,27 +57,27 @@ fn from_iterator() {
5657
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1,2,3]);
5758
}
5859

59-
/* ToDo: This requires FutureExt::select to be implemented
6060
#[test]
6161
fn queue_never_unblocked() {
62-
let (_a_tx, a_rx) = oneshot::channel::<Box<Any+Send>>();
63-
let (b_tx, b_rx) = oneshot::channel::<Box<Any+Send>>();
64-
let (c_tx, c_rx) = oneshot::channel::<Box<Any+Send>>();
62+
let (_a_tx, a_rx) = oneshot::channel::<Box<dyn Any + Send>>();
63+
let (b_tx, b_rx) = oneshot::channel::<Box<dyn Any + Send>>();
64+
let (c_tx, c_rx) = oneshot::channel::<Box<dyn Any + Send>>();
6565

6666
let mut stream = vec![
67-
Box::new(a_rx) as Box<Future<Item = _, Error = _>>,
68-
Box::new(b_rx.select(c_rx).then(|res| Ok(Box::new(res) as Box<Any+Send>))) as _,
67+
Box::new(a_rx) as Box<dyn Future<Output = _> + Unpin>,
68+
Box::new(future::try_select(b_rx, c_rx)
69+
.map_err(|e| e.factor_first().0)
70+
.and_then(|e| future::ok(Box::new(e) as Box<dyn Any + Send>))) as _,
6971
].into_iter().collect::<FuturesOrdered<_>>();
7072

71-
with_no_spawn_context(|cx| {
72-
for _ in 0..10 {
73-
assert!(stream.poll_next(cx).unwrap().is_pending());
74-
}
73+
let cx = &mut noop_context();
74+
for _ in 0..10 {
75+
assert!(stream.poll_next_unpin(cx).is_pending());
76+
}
7577

76-
b_tx.send(Box::new(())).unwrap();
77-
assert!(stream.poll_next(cx).unwrap().is_pending());
78-
c_tx.send(Box::new(())).unwrap();
79-
assert!(stream.poll_next(cx).unwrap().is_pending());
80-
assert!(stream.poll_next(cx).unwrap().is_pending());
81-
})
82-
}*/
78+
b_tx.send(Box::new(())).unwrap();
79+
assert!(stream.poll_next_unpin(cx).is_pending());
80+
c_tx.send(Box::new(())).unwrap();
81+
assert!(stream.poll_next_unpin(cx).is_pending());
82+
assert!(stream.poll_next_unpin(cx).is_pending());
83+
}

futures/tests/futures_unordered.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures::channel::oneshot;
22
use futures::executor::{block_on, block_on_stream};
3-
use futures::future::{self, join, FutureExt};
3+
use futures::future::{self, join, Future, FutureExt};
44
use futures::stream::{StreamExt, FuturesUnordered};
55
use futures::task::Poll;
66
use futures_test::{assert_stream_done, assert_stream_next};
@@ -57,30 +57,28 @@ fn from_iterator() {
5757
assert_eq!(block_on(stream.collect::<Vec<_>>()), vec![1,2,3]);
5858
}
5959

60-
/* ToDo: This requires FutureExt::select to be implemented
6160
#[test]
6261
fn finished_future() {
6362
let (_a_tx, a_rx) = oneshot::channel::<i32>();
6463
let (b_tx, b_rx) = oneshot::channel::<i32>();
6564
let (c_tx, c_rx) = oneshot::channel::<i32>();
6665

6766
let mut stream = vec![
68-
a_rx.boxed(),
69-
b_rx.select(c_rx).boxed(),
67+
Box::new(a_rx) as Box<dyn Future<Output = Result<_, _>> + Unpin>,
68+
Box::new(future::select(b_rx, c_rx).map(|e| e.factor_first().0)) as _,
7069
].into_iter().collect::<FuturesUnordered<_>>();
7170

72-
support::with_noop_waker_context(f)(|cx| {
73-
for _ in 0..10 {
74-
assert!(stream.poll_next_unpin(cx).is_pending());
75-
}
76-
77-
b_tx.send(12).unwrap();
78-
assert!(stream.poll_next_unpin(cx).is_ready());
79-
c_tx.send(3).unwrap();
80-
assert!(stream.poll_next_unpin(cx).is_pending());
71+
let cx = &mut noop_context();
72+
for _ in 0..10 {
8173
assert!(stream.poll_next_unpin(cx).is_pending());
82-
})
83-
}*/
74+
}
75+
76+
b_tx.send(12).unwrap();
77+
c_tx.send(3).unwrap();
78+
assert!(stream.poll_next_unpin(cx).is_ready());
79+
assert!(stream.poll_next_unpin(cx).is_pending());
80+
assert!(stream.poll_next_unpin(cx).is_pending());
81+
}
8482

8583
#[test]
8684
fn iter_mut_cancel() {

futures/tests/shared.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures::channel::oneshot;
22
use futures::executor::{block_on, LocalPool};
3-
use futures::future::{self, FutureExt, LocalFutureObj};
3+
use futures::future::{self, FutureExt, TryFutureExt, LocalFutureObj};
44
use futures::task::LocalSpawn;
55
use std::cell::{Cell, RefCell};
66
use std::rc::Rc;
@@ -41,7 +41,6 @@ fn many_threads() {
4141
send_shared_oneshot_and_wait_on_multiple_threads(1000);
4242
}
4343

44-
/* ToDo: This requires FutureExt::select to be implemented
4544
#[test]
4645
fn drop_on_one_task_ok() {
4746
let (tx, rx) = oneshot::channel::<u32>();
@@ -51,14 +50,14 @@ fn drop_on_one_task_ok() {
5150
let (tx2, rx2) = oneshot::channel::<u32>();
5251

5352
let t1 = thread::spawn(|| {
54-
let f = f1.map_err(|_| ()).map(|x| *x).select(rx2.map_err(|_| ()));
53+
let f = future::try_select(f1.map_err(|_| ()), rx2.map_err(|_| ()));
5554
drop(block_on(f));
5655
});
5756

5857
let (tx3, rx3) = oneshot::channel::<u32>();
5958

6059
let t2 = thread::spawn(|| {
61-
let _ = block_on(f2.map(|x| tx3.send(*x).unwrap()).map_err(|_| ()));
60+
let _ = block_on(f2.map_ok(|x| tx3.send(x).unwrap()).map_err(|_| ()));
6261
});
6362

6463
tx2.send(11).unwrap(); // cancel `f1`
@@ -68,7 +67,7 @@ fn drop_on_one_task_ok() {
6867
let result = block_on(rx3).unwrap();
6968
assert_eq!(result, 42);
7069
t2.join().unwrap();
71-
}*/
70+
}
7271

7372
#[test]
7473
fn drop_in_poll() {

0 commit comments

Comments
 (0)