diff options
author | Carl Lerche <me@carllerche.com> | 2019-06-26 17:06:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-26 17:06:56 -0700 |
commit | 1f47ed3dcc4b582315cdbfb195495d7d4c76d3f3 (patch) | |
tree | 0b9ca199a6b5e5539d75e4fe46dbc7563bb1b20c /tokio/tests/io_copy.rs | |
parent | e9aaacddbda25eeb56a40e4f5e85d616d5e08b74 (diff) |
tokio: rewrite io_read.rs test to use async/await (#1207)
This simplifies the test
Diffstat (limited to 'tokio/tests/io_copy.rs')
-rw-r--r-- | tokio/tests/io_copy.rs | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/tokio/tests/io_copy.rs b/tokio/tests/io_copy.rs index ee972681..0179cfb7 100644 --- a/tokio/tests/io_copy.rs +++ b/tokio/tests/io_copy.rs @@ -1,18 +1,16 @@ #![deny(warnings, rust_2018_idioms)] +#![feature(async_await)] use tokio::io::{AsyncRead, AsyncWrite, AsyncReadExt}; -use tokio_test::assert_ready_ok; -use tokio_test::task::MockTask; +use tokio_test::assert_ok; use bytes::BytesMut; -use pin_utils::pin_mut; -use std::future::Future; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; -#[test] -fn copy() { +#[tokio::test] +async fn copy() { struct Rd(bool); impl AsyncRead for Rd { @@ -54,18 +52,10 @@ fn copy() { } let buf = BytesMut::with_capacity(64); - let mut task = MockTask::new(); + let mut rd = Rd(true); + let mut wr = Wr(buf); - task.enter(|cx| { - let mut rd = Rd(true); - let mut wr = Wr(buf); - - let copy = rd.copy(&mut wr); - pin_mut!(copy); - - let n = assert_ready_ok!(copy.poll(cx)); - - assert_eq!(n, 11); - assert_eq!(wr.0[..], b"hello world"[..]); - }); + let n = assert_ok!(rd.copy(&mut wr).await); + assert_eq!(n, 11); + assert_eq!(wr.0[..], b"hello world"[..]); } |