|
| 1 | +use std::sync::Arc; |
| 2 | + |
1 | 3 | use futures::channel::mpsc; |
2 | 4 | use futures::executor::block_on; |
3 | 5 | use futures::future::{self, Future}; |
| 6 | +use futures::lock::Mutex; |
4 | 7 | use futures::sink::SinkExt; |
5 | 8 | use futures::stream::{self, StreamExt}; |
6 | 9 | use futures::task::Poll; |
7 | | -use futures::FutureExt; |
| 10 | +use futures::{ready, FutureExt}; |
8 | 11 | use futures_test::task::noop_context; |
9 | 12 |
|
10 | 13 | #[test] |
@@ -243,6 +246,49 @@ fn flatten_unordered() { |
243 | 246 | assert_eq!(fm_unordered, fl_unordered); |
244 | 247 | assert_eq!(fm_unordered, (0..60).collect::<Vec<u8>>()); |
245 | 248 | }); |
| 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 | + } |
246 | 292 | } |
247 | 293 |
|
248 | 294 | #[cfg(feature = "executor")] // executor:: |
|
0 commit comments