Skip to content

Commit dd5d065

Browse files
tokio-utils: add miri test suite
1 parent 46f17cc commit dd5d065

20 files changed

+106
-84
lines changed

tokio-test/macros/src/expend.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ pub fn tokio_test(args: TokenStream, item_fn: ItemFn) -> TokenStream {
5656
}
5757
}
5858
}
59-
panic!(
60-
"unknown config `{}`",
61-
meta.path().to_token_stream().to_string()
62-
)
59+
panic!("unknown config `{}`", meta.path().to_token_stream())
6360
});
6461
let runtime_type = quote(|t| {
6562
if id_multi_thread {

tokio-util/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ hashbrown = { version = "0.14.0", default-features = false, optional = true }
5151
tokio = { version = "1.0.0", path = "../tokio", features = ["full"] }
5252
tokio-test = { version = "0.4.0", path = "../tokio-test" }
5353
tokio-stream = { version = "0.1", path = "../tokio-stream" }
54+
tokio-test-macros = { path = "../tokio-test/macros" }
5455

5556
async-stream = "0.3.0"
5657
futures = "0.3.0"

tokio-util/src/either.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ mod tests {
202202
use super::*;
203203
use tokio::io::{repeat, AsyncReadExt, Repeat};
204204
use tokio_stream::{once, Once, StreamExt};
205+
use tokio_test_macros::tokio_test;
205206

206-
#[tokio::test]
207+
#[tokio_test(miri)]
207208
async fn either_is_stream() {
208209
let mut either: Either<Once<u32>, Once<u32>> = Either::Left(once(1));
209210

210211
assert_eq!(Some(1u32), either.next().await);
211212
}
212213

213-
#[tokio::test]
214+
#[tokio_test(miri)]
214215
async fn either_is_async_read() {
215216
let mut buffer = [0; 3];
216217
let mut either: Either<Repeat, Repeat> = Either::Right(repeat(0b101));

tokio-util/tests/abort_on_drop.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use tokio::sync::oneshot;
2+
use tokio_test_macros::tokio_test;
23
use tokio_util::task::AbortOnDropHandle;
34

4-
#[tokio::test]
5+
#[tokio_test]
56
async fn aborts_task_on_drop() {
67
let (mut tx, rx) = oneshot::channel::<bool>();
78
let handle = tokio::spawn(async move {
@@ -13,7 +14,7 @@ async fn aborts_task_on_drop() {
1314
assert!(tx.is_closed());
1415
}
1516

16-
#[tokio::test]
17+
#[tokio_test]
1718
async fn aborts_task_directly() {
1819
let (mut tx, rx) = oneshot::channel::<bool>();
1920
let handle = tokio::spawn(async move {

tokio-util/tests/compat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use futures_io::SeekFrom;
66
use futures_util::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt};
77
use tempfile::NamedTempFile;
88
use tokio::fs::OpenOptions;
9+
use tokio_test_macros::tokio_test;
910
use tokio_util::compat::TokioAsyncWriteCompatExt;
1011

11-
#[tokio::test]
12+
#[tokio_test]
1213
async fn compat_file_seek() -> futures_util::io::Result<()> {
1314
let temp_file = NamedTempFile::new()?;
1415
let mut file = OpenOptions::new()

tokio-util/tests/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use tokio::time::*;
77
use tokio_util::context::RuntimeExt;
88

99
#[test]
10+
#[cfg_attr(miri, ignore)]
1011
fn tokio_context_with_another_runtime() {
1112
let rt1 = Builder::new_multi_thread()
1213
.worker_threads(1)

tokio-util/tests/framed.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use tokio_stream::StreamExt;
44
use tokio_test::assert_ok;
5+
use tokio_test_macros::tokio_test;
56
use tokio_util::codec::{Decoder, Encoder, Framed, FramedParts};
67

78
use bytes::{Buf, BufMut, BytesMut};
@@ -97,7 +98,7 @@ impl tokio::io::AsyncRead for DontReadIntoThis {
9798
}
9899
}
99100

100-
#[tokio::test]
101+
#[tokio_test(miri)]
101102
async fn can_read_from_existing_buf() {
102103
let mut parts = FramedParts::new(DontReadIntoThis, U32Codec::default());
103104
parts.read_buf = BytesMut::from(&[0, 0, 0, 42][..]);
@@ -109,7 +110,7 @@ async fn can_read_from_existing_buf() {
109110
assert_eq!(framed.codec().read_bytes, 4);
110111
}
111112

112-
#[tokio::test]
113+
#[tokio_test(miri)]
113114
async fn can_read_from_existing_buf_after_codec_changed() {
114115
let mut parts = FramedParts::new(DontReadIntoThis, U32Codec::default());
115116
parts.read_buf = BytesMut::from(&[0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 0, 84][..]);

tokio-util/tests/framed_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use futures_core::stream::Stream;
2+
use tokio_test_macros::tokio_test;
23
use std::{io, pin::Pin};
34
use tokio_test::{assert_ready, io::Builder, task};
45
use tokio_util::codec::{BytesCodec, FramedRead};
@@ -16,7 +17,7 @@ macro_rules! assert_read {
1617
}};
1718
}
1819

19-
#[tokio::test]
20+
#[tokio_test(miri)]
2021
async fn return_none_after_error() {
2122
let mut io = FramedRead::new(
2223
Builder::new()

tokio-util/tests/io_inspect.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
task::{Context, Poll},
66
};
77
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
8+
use tokio_test_macros::tokio_test;
89
use tokio_util::io::{InspectReader, InspectWriter};
910

1011
/// An AsyncRead implementation that works byte-by-byte, to catch out callers
@@ -28,7 +29,7 @@ impl AsyncRead for SmallReader {
2829
}
2930
}
3031

31-
#[tokio::test]
32+
#[tokio_test(miri)]
3233
async fn read_tee() {
3334
let contents = b"This could be really long, you know".to_vec();
3435
let reader = SmallReader {
@@ -110,7 +111,7 @@ impl AsyncWrite for SmallWriter {
110111
}
111112
}
112113

113-
#[tokio::test]
114+
#[tokio_test(miri)]
114115
async fn write_tee() {
115116
let mut altout: Vec<u8> = Vec::new();
116117
let mut writeout = SmallWriter {
@@ -157,7 +158,7 @@ async fn write_all_vectored<W: AsyncWrite + Unpin>(
157158
Ok(res)
158159
}
159160

160-
#[tokio::test]
161+
#[tokio_test(miri)]
161162
async fn write_tee_vectored() {
162163
let mut altout: Vec<u8> = Vec::new();
163164
let mut writeout = SmallWriter {

tokio-util/tests/io_reader_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::pin::Pin;
44
use std::task::{Context, Poll};
55
use tokio::io::{AsyncRead, ReadBuf};
66
use tokio_stream::StreamExt;
7+
use tokio_test_macros::tokio_test;
78

89
/// produces at most `remaining` zeros, that returns error.
910
/// each time it reads at most 31 byte.
@@ -34,7 +35,7 @@ impl AsyncRead for Reader {
3435
}
3536
}
3637

37-
#[tokio::test]
38+
#[tokio_test] // Too slow on miri
3839
async fn correct_behavior_on_errors() {
3940
let reader = Reader { remaining: 8000 };
4041
let mut stream = tokio_util::io::ReaderStream::new(reader);

0 commit comments

Comments
 (0)