summaryrefslogtreecommitdiffstats
path: root/tokio/tests
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2020-09-24 17:26:03 -0700
committerGitHub <noreply@github.com>2020-09-24 17:26:03 -0700
commit4186b0aa38abbec7670d53882d5cdfd4b12add5c (patch)
treeb067117fcb1a4c479cd274465bcac0431c2e59f7 /tokio/tests
parent760ae89401d9addb71ebf19674980577b5501edd (diff)
io: remove poll_{read,write}_buf from traits (#2882)
These functions have object safety issues. It also has been decided to avoid vectored operations on the I/O traits. A later PR will bring back vectored operations on specific types that support them. Refs: #2879, #2716
Diffstat (limited to 'tokio/tests')
-rw-r--r--tokio/tests/io_async_read.rs105
1 files changed, 1 insertions, 104 deletions
diff --git a/tokio/tests/io_async_read.rs b/tokio/tests/io_async_read.rs
index d1aae9a1..aaeadfa4 100644
--- a/tokio/tests/io_async_read.rs
+++ b/tokio/tests/io_async_read.rs
@@ -1,113 +1,10 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
-use tokio::io::{AsyncRead, ReadBuf};
-use tokio_test::task;
-use tokio_test::{assert_ready_err, assert_ready_ok};
-
-use bytes::BytesMut;
-use std::io;
-use std::pin::Pin;
-use std::task::{Context, Poll};
+use tokio::io::AsyncRead;
#[test]
fn assert_obj_safe() {
fn _assert<T>() {}
_assert::<Box<dyn AsyncRead>>();
}
-
-#[test]
-fn read_buf_success() {
- struct Rd;
-
- impl AsyncRead for Rd {
- fn poll_read(
- self: Pin<&mut Self>,
- _cx: &mut Context<'_>,
- buf: &mut ReadBuf<'_>,
- ) -> Poll<io::Result<()>> {
- buf.append(b"hello world");
- Poll::Ready(Ok(()))
- }
- }
-
- let mut buf = BytesMut::with_capacity(65);
-
- task::spawn(Rd).enter(|cx, rd| {
- let n = assert_ready_ok!(rd.poll_read_buf(cx, &mut buf));
-
- assert_eq!(11, n);
- assert_eq!(buf[..], b"hello world"[..]);
- });
-}
-
-#[test]
-fn read_buf_error() {
- struct Rd;
-
- impl AsyncRead for Rd {
- fn poll_read(
- self: Pin<&mut Self>,
- _cx: &mut Context<'_>,
- _buf: &mut ReadBuf<'_>,
- ) -> Poll<io::Result<()>> {
- let err = io::ErrorKind::Other.into();
- Poll::Ready(Err(err))
- }
- }
-
- let mut buf = BytesMut::with_capacity(65);
-
- task::spawn(Rd).enter(|cx, rd| {
- let err = assert_ready_err!(rd.poll_read_buf(cx, &mut buf));
- assert_eq!(err.kind(), io::ErrorKind::Other);
- });
-}
-
-#[test]
-fn read_buf_no_capacity() {
- struct Rd;
-
- impl AsyncRead for Rd {
- fn poll_read(
- self: Pin<&mut Self>,
- _cx: &mut Context<'_>,
- _buf: &mut ReadBuf<'_>,
- ) -> Poll<io::Result<()>> {
- unimplemented!();
- }
- }
-
- let mut buf = [0u8; 0];
-
- task::spawn(Rd).enter(|cx, rd| {
- let n = assert_ready_ok!(rd.poll_read_buf(cx, &mut &mut buf[..]));
- assert_eq!(0, n);
- });
-}
-
-#[test]
-fn read_buf_uninitialized_ok() {
- struct Rd;
-
- impl AsyncRead for Rd {
- fn poll_read(
- self: Pin<&mut Self>,
- _cx: &mut Context<'_>,
- buf: &mut ReadBuf<'_>,
- ) -> Poll<io::Result<()>> {
- assert_eq!(buf.remaining(), 64);
- assert_eq!(buf.filled().len(), 0);
- assert_eq!(buf.initialized().len(), 0);
- Poll::Ready(Ok(()))
- }
- }
-
- // Can't create BytesMut w/ zero capacity, so fill it up
- let mut buf = BytesMut::with_capacity(64);
-
- task::spawn(Rd).enter(|cx, rd| {
- let n = assert_ready_ok!(rd.poll_read_buf(cx, &mut buf));
- assert_eq!(0, n);
- });
-}