Skip to content

Commit b5928ba

Browse files
authored
chore(rw-stream-sink): use tokio instead of async-std in tests
ref libp2p#4449 I think this is the last one in this issue. If you let me know, I can use "closes" to close the issue. Pull-Request: libp2p#6023.
1 parent 3cf42f1 commit b5928ba

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/rw-stream-sink/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pin-project = "1.1.5"
1616
static_assertions = "1"
1717

1818
[dev-dependencies]
19-
async-std = "1.0"
19+
tokio = { workspace = true, features = ["rt", "macros"] }
2020

2121
# Passing arguments to the docsrs builder in order to properly document cfg's.
2222
# More information: https://docs.rs/about/builds#cross-compiling

misc/rw-stream-sink/src/lib.rs

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ mod tests {
121121
task::{Context, Poll},
122122
};
123123

124-
use async_std::task;
125124
use futures::{channel::mpsc, prelude::*};
126125

127126
use super::RwStreamSink;
@@ -165,58 +164,52 @@ mod tests {
165164
}
166165
}
167166

168-
#[test]
169-
fn basic_reading() {
167+
#[tokio::test]
168+
async fn basic_reading() {
170169
let (tx1, _) = mpsc::channel::<Vec<u8>>(10);
171170
let (mut tx2, rx2) = mpsc::channel(10);
172171

173172
let mut wrapper = RwStreamSink::new(Wrapper(rx2.map(Ok), tx1));
174173

175-
task::block_on(async move {
176-
tx2.send(Vec::from("hel")).await.unwrap();
177-
tx2.send(Vec::from("lo wor")).await.unwrap();
178-
tx2.send(Vec::from("ld")).await.unwrap();
179-
tx2.close().await.unwrap();
174+
tx2.send(Vec::from("hel")).await.unwrap();
175+
tx2.send(Vec::from("lo wor")).await.unwrap();
176+
tx2.send(Vec::from("ld")).await.unwrap();
177+
tx2.close().await.unwrap();
180178

181-
let mut data = Vec::new();
182-
wrapper.read_to_end(&mut data).await.unwrap();
183-
assert_eq!(data, b"hello world");
184-
})
179+
let mut data = Vec::new();
180+
wrapper.read_to_end(&mut data).await.unwrap();
181+
assert_eq!(data, b"hello world");
185182
}
186183

187-
#[test]
188-
fn skip_empty_stream_items() {
184+
#[tokio::test]
185+
async fn skip_empty_stream_items() {
189186
let data: Vec<&[u8]> = vec![b"", b"foo", b"", b"bar", b"", b"baz", b""];
190187
let mut rws = RwStreamSink::new(stream::iter(data).map(Ok));
191188
let mut buf = [0; 9];
192-
task::block_on(async move {
193-
assert_eq!(3, rws.read(&mut buf).await.unwrap());
194-
assert_eq!(3, rws.read(&mut buf[3..]).await.unwrap());
195-
assert_eq!(3, rws.read(&mut buf[6..]).await.unwrap());
196-
assert_eq!(0, rws.read(&mut buf).await.unwrap());
197-
assert_eq!(b"foobarbaz", &buf[..])
198-
})
189+
assert_eq!(3, rws.read(&mut buf).await.unwrap());
190+
assert_eq!(3, rws.read(&mut buf[3..]).await.unwrap());
191+
assert_eq!(3, rws.read(&mut buf[6..]).await.unwrap());
192+
assert_eq!(0, rws.read(&mut buf).await.unwrap());
193+
assert_eq!(b"foobarbaz", &buf[..])
199194
}
200195

201-
#[test]
202-
fn partial_read() {
196+
#[tokio::test]
197+
async fn partial_read() {
203198
let data: Vec<&[u8]> = vec![b"hell", b"o world"];
204199
let mut rws = RwStreamSink::new(stream::iter(data).map(Ok));
205200
let mut buf = [0; 3];
206-
task::block_on(async move {
207-
assert_eq!(3, rws.read(&mut buf).await.unwrap());
208-
assert_eq!(b"hel", &buf[..3]);
209-
assert_eq!(0, rws.read(&mut buf[..0]).await.unwrap());
210-
assert_eq!(1, rws.read(&mut buf).await.unwrap());
211-
assert_eq!(b"l", &buf[..1]);
212-
assert_eq!(3, rws.read(&mut buf).await.unwrap());
213-
assert_eq!(b"o w", &buf[..3]);
214-
assert_eq!(0, rws.read(&mut buf[..0]).await.unwrap());
215-
assert_eq!(3, rws.read(&mut buf).await.unwrap());
216-
assert_eq!(b"orl", &buf[..3]);
217-
assert_eq!(1, rws.read(&mut buf).await.unwrap());
218-
assert_eq!(b"d", &buf[..1]);
219-
assert_eq!(0, rws.read(&mut buf).await.unwrap());
220-
})
201+
assert_eq!(3, rws.read(&mut buf).await.unwrap());
202+
assert_eq!(b"hel", &buf[..3]);
203+
assert_eq!(0, rws.read(&mut buf[..0]).await.unwrap());
204+
assert_eq!(1, rws.read(&mut buf).await.unwrap());
205+
assert_eq!(b"l", &buf[..1]);
206+
assert_eq!(3, rws.read(&mut buf).await.unwrap());
207+
assert_eq!(b"o w", &buf[..3]);
208+
assert_eq!(0, rws.read(&mut buf[..0]).await.unwrap());
209+
assert_eq!(3, rws.read(&mut buf).await.unwrap());
210+
assert_eq!(b"orl", &buf[..3]);
211+
assert_eq!(1, rws.read(&mut buf).await.unwrap());
212+
assert_eq!(b"d", &buf[..1]);
213+
assert_eq!(0, rws.read(&mut buf).await.unwrap());
221214
}
222215
}

0 commit comments

Comments
 (0)