Skip to content

Commit 9bc4e4e

Browse files
committed
FlattenUnordered: check waker panic
1 parent 15f5866 commit 9bc4e4e

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

futures/tests/stream.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
use std::sync::Arc;
2+
13
use futures::channel::mpsc;
24
use futures::executor::block_on;
35
use futures::future::{self, Future};
6+
use futures::lock::Mutex;
47
use futures::sink::SinkExt;
58
use futures::stream::{self, StreamExt};
69
use futures::task::Poll;
7-
use futures::FutureExt;
10+
use futures::{ready, FutureExt};
811
use futures_test::task::noop_context;
912

1013
#[test]
@@ -243,6 +246,49 @@ fn flatten_unordered() {
243246
assert_eq!(fm_unordered, fl_unordered);
244247
assert_eq!(fm_unordered, (0..60).collect::<Vec<u8>>());
245248
});
249+
250+
// waker panics
251+
{
252+
let stream = Arc::new(Mutex::new(
253+
Interchanger { polled: false, base: 0, wake_immediately: false }
254+
.take(10)
255+
.flat_map_unordered(10, |s| s.map(identity)),
256+
));
257+
258+
struct PanicWaker;
259+
260+
impl ArcWake for PanicWaker {
261+
fn wake_by_ref(_arc_self: &Arc<Self>) {
262+
panic!("WAKE UP");
263+
}
264+
}
265+
266+
std::thread::spawn({
267+
let stream = stream.clone();
268+
move || {
269+
let mut st = poll_fn(|cx| {
270+
let mut lock = ready!(stream.lock().poll_unpin(cx));
271+
272+
let panic_waker = waker(Arc::new(PanicWaker));
273+
let mut panic_cx = Context::from_waker(&panic_waker);
274+
let data = ready!(lock.poll_next_unpin(&mut panic_cx));
275+
276+
Poll::Ready(data)
277+
});
278+
279+
block_on(st.next())
280+
}
281+
})
282+
.join()
283+
.unwrap_err();
284+
285+
block_on(async move {
286+
let mut values: Vec<_> = stream.lock().await.by_ref().collect().await;
287+
values.sort();
288+
289+
assert_eq!(values, (0..60).collect::<Vec<u8>>());
290+
});
291+
}
246292
}
247293

248294
#[cfg(feature = "executor")] // executor::

0 commit comments

Comments
 (0)