Skip to content

Commit f4edc67

Browse files
committed
Tweak cpupool tests a bit
1 parent 79adf8b commit f4edc67

File tree

1 file changed

+6
-48
lines changed

1 file changed

+6
-48
lines changed

futures-cpupool/tests/smoke.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,12 @@ extern crate futures;
22
extern crate futures_cpupool;
33

44
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
5-
use std::sync::mpsc::channel;
65
use std::thread;
76
use std::time::Duration;
87

98
use futures::{Future, BoxFuture};
10-
use futures::task::{Executor, Task, Run};
119
use futures_cpupool::CpuPool;
1210

13-
// TODO: centralize this?
14-
pub trait ForgetExt {
15-
fn forget(self);
16-
}
17-
18-
impl<F> ForgetExt for F
19-
where F: Future + Sized + Send + 'static,
20-
F::Item: Send,
21-
F::Error: Send
22-
{
23-
fn forget(self) {
24-
use std::sync::Arc;
25-
26-
struct ForgetExec;
27-
28-
impl Executor for ForgetExec {
29-
fn execute(&self, run: Run) {
30-
run.run()
31-
}
32-
}
33-
34-
Task::new(Arc::new(ForgetExec), self.then(|_| Ok(())).boxed()).unpark();
35-
}
36-
}
37-
38-
39-
fn get<F>(f: F) -> Result<F::Item, F::Error>
40-
where F: Future + Send + 'static,
41-
F::Item: Send,
42-
F::Error: Send,
43-
{
44-
let (tx, rx) = channel();
45-
f.then(move |res| {
46-
tx.send(res).unwrap();
47-
futures::finished::<(), ()>(())
48-
}).forget();
49-
rx.recv().unwrap()
50-
}
51-
5211
fn done<T: Send + 'static>(t: T) -> BoxFuture<T, ()> {
5312
futures::done(Ok(t)).boxed()
5413
}
@@ -58,7 +17,7 @@ fn join() {
5817
let pool = CpuPool::new(2);
5918
let a = pool.spawn(done(1));
6019
let b = pool.spawn(done(2));
61-
let res = get(a.join(b).map(|(a, b)| a + b));
20+
let res = a.join(b).map(|(a, b)| a + b).wait();
6221

6322
assert_eq!(res.unwrap(), 3);
6423
}
@@ -68,8 +27,8 @@ fn select() {
6827
let pool = CpuPool::new(2);
6928
let a = pool.spawn(done(1));
7029
let b = pool.spawn(done(2));
71-
let (item1, next) = get(a.select(b)).ok().unwrap();
72-
let item2 = get(next).unwrap();
30+
let (item1, next) = a.select(b).wait().ok().unwrap();
31+
let item2 = next.wait().unwrap();
7332

7433
assert!(item1 != item2);
7534
assert!((item1 == 1 && item2 == 2) || (item1 == 2 && item2 == 1));
@@ -90,11 +49,10 @@ fn threads_go_away() {
9049
thread_local!(static FOO: A = A);
9150

9251
let pool = CpuPool::new(2);
93-
get(pool.spawn(futures::lazy(|| {
52+
let _handle = pool.spawn(futures::lazy(|| {
9453
FOO.with(|_| ());
95-
let res: Result<(), ()> = Ok(());
96-
res
97-
}))).unwrap();
54+
Ok::<(), ()>(())
55+
}));
9856
drop(pool);
9957

10058
for _ in 0..100 {

0 commit comments

Comments
 (0)