diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-10-27 09:30:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 09:30:29 +0100 |
commit | fe2b9976755407b85c82b5cdee9d8c5e16e3d6c6 (patch) | |
tree | 65d9278870691e102cbcc8122782fe75104d2894 /tokio/tests | |
parent | 6d0ba19af51015dcd80558ae768215448e285fdf (diff) |
util: upgrade tokio-util to bytes 0.6 (#3052)
Diffstat (limited to 'tokio/tests')
-rw-r--r-- | tokio/tests/io_read_buf.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tokio/tests/io_read_buf.rs b/tokio/tests/io_read_buf.rs index 0328168d..35c12126 100644 --- a/tokio/tests/io_read_buf.rs +++ b/tokio/tests/io_read_buf.rs @@ -4,6 +4,7 @@ use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf}; use tokio_test::assert_ok; +use futures::future::poll_fn; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; @@ -34,3 +35,38 @@ async fn read_buf() { assert_eq!(n, 11); assert_eq!(buf[..], b"hello world"[..]); } + +#[tokio::test] +async fn poll_read_buf() { + struct Rd { + cnt: usize, + } + + impl AsyncRead for Rd { + fn poll_read( + mut self: Pin<&mut Self>, + _cx: &mut Context<'_>, + buf: &mut ReadBuf<'_>, + ) -> Poll<io::Result<()>> { + self.cnt += 1; + buf.put_slice(b"hello world"); + Poll::Ready(Ok(())) + } + } + + let mut buf = vec![]; + let mut rd = Rd { cnt: 0 }; + + let res = tokio::spawn(async move { + poll_fn(|cx| { + let res = rd.poll_read_buf(&mut buf, cx); + assert_eq!(1, rd.cnt); + assert_eq!(buf[..], b"hello world"[..]); + res + }) + .await + }) + .await; + + assert!(matches!(res, Ok(Ok(11usize)))); +} |