Skip to content

Commit

Permalink
io: add test for take bug (#4443)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Feb 2, 2022
1 parent 1bb4d23 commit 5957946
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tokio/tests/io_take.rs
Expand Up @@ -17,6 +17,23 @@ async fn take() {
assert_eq!(&buf, &b"hell\0\0"[..]);
}

#[tokio::test]
async fn issue_4435() {
let mut buf = [0; 8];
let rd: &[u8] = b"hello world";

let rd = rd.take(4);
tokio::pin!(rd);

let mut read_buf = ReadBuf::new(&mut buf);
read_buf.put_slice(b"AB");

futures::future::poll_fn(|cx| rd.as_mut().poll_read(cx, &mut read_buf))
.await
.unwrap();
assert_eq!(&buf, &b"ABhell\0\0"[..]);
}

struct BadReader;

impl AsyncRead for BadReader {
Expand Down

0 comments on commit 5957946

Please sign in to comment.