Skip to content

Commit 6c5c648

Browse files
tmiaskocramertj
authored andcommitted
Add regression test for issue 1834
1 parent fd694b8 commit 6c5c648

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

futures/tests/sink.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,32 @@ fn with_flat_map() {
224224
assert_eq!(sink.get_ref(), &[1, 2, 2, 3, 3, 3]);
225225
}
226226

227+
// Check that `with` propagates `poll_ready` to the inner sink.
228+
// Regression test for the issue #1834.
229+
#[test]
230+
fn with_propagates_poll_ready() {
231+
let (tx, mut rx) = mpsc::channel::<i32>(0);
232+
let mut tx = tx.with(|item: i32| future::ok::<i32, mpsc::SendError>(item + 10));
233+
234+
block_on(future::lazy(|_| {
235+
flag_cx(|flag, cx| {
236+
let mut tx = Pin::new(&mut tx);
237+
238+
// Should be ready for the first item.
239+
assert_eq!(tx.as_mut().poll_ready(cx), Poll::Ready(Ok(())));
240+
assert_eq!(tx.as_mut().start_send(0), Ok(()));
241+
242+
// Should be ready for the second item only after the first one is received.
243+
assert_eq!(tx.as_mut().poll_ready(cx), Poll::Pending);
244+
assert!(!flag.get());
245+
sassert_next(&mut rx, 10);
246+
assert!(flag.get());
247+
assert_eq!(tx.as_mut().poll_ready(cx), Poll::Ready(Ok(())));
248+
assert_eq!(tx.as_mut().start_send(1), Ok(()));
249+
})
250+
}));
251+
}
252+
227253
// Immediately accepts all requests to start pushing, but completion is managed
228254
// by manually flushing
229255
struct ManualFlush<T: Unpin> {

0 commit comments

Comments
 (0)