Skip to content

Commit 0e6924c

Browse files
authored
chore(libp2p-uds): use tokio instead of async_std in tests
ref libp2p#4449 Pull-Request: libp2p#6031.
1 parent 8199dac commit 0e6924c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

transports/uds/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tracing = { workspace = true }
1919

2020
[dev-dependencies]
2121
tempfile = "3.10"
22+
tokio = { workspace = true, features = ["rt", "macros", "io-util"] }
2223

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

transports/uds/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn multiaddr_to_path(addr: &Multiaddr) -> Result<PathBuf, ()> {
242242
}
243243
}
244244

245-
#[cfg(all(test, feature = "async-std"))]
245+
#[cfg(all(test, feature = "tokio"))]
246246
mod tests {
247247
use std::{borrow::Cow, path::Path};
248248

@@ -252,8 +252,9 @@ mod tests {
252252
transport::{DialOpts, ListenerId, PortUse},
253253
Endpoint, Transport,
254254
};
255+
use tokio::io::{AsyncReadExt, AsyncWriteExt};
255256

256-
use super::{multiaddr_to_path, UdsConfig};
257+
use super::{multiaddr_to_path, TokioUdsConfig};
257258

258259
#[test]
259260
fn multiaddr_to_path_conversion() {
@@ -271,8 +272,8 @@ mod tests {
271272
);
272273
}
273274

274-
#[test]
275-
fn communicating_between_dialer_and_listener() {
275+
#[tokio::test]
276+
async fn communicating_between_dialer_and_listener() {
276277
let temp_dir = tempfile::tempdir().unwrap();
277278
let socket = temp_dir.path().join("socket");
278279
let addr = Multiaddr::from(Protocol::Unix(Cow::Owned(
@@ -281,8 +282,8 @@ mod tests {
281282

282283
let (tx, rx) = oneshot::channel();
283284

284-
async_std::task::spawn(async move {
285-
let mut transport = UdsConfig::new().boxed();
285+
let listener = async move {
286+
let mut transport = TokioUdsConfig::new().boxed();
286287
transport.listen_on(ListenerId::next(), addr).unwrap();
287288

288289
let listen_addr = transport
@@ -303,10 +304,10 @@ mod tests {
303304
let mut buf = [0u8; 3];
304305
sock.read_exact(&mut buf).await.unwrap();
305306
assert_eq!(buf, [1, 2, 3]);
306-
});
307+
};
307308

308-
async_std::task::block_on(async move {
309-
let mut uds = UdsConfig::new();
309+
let dialer = async move {
310+
let mut uds = TokioUdsConfig::new();
310311
let addr = rx.await.unwrap();
311312
let mut socket = uds
312313
.dial(
@@ -320,13 +321,15 @@ mod tests {
320321
.await
321322
.unwrap();
322323
let _ = socket.write(&[1, 2, 3]).await.unwrap();
323-
});
324+
};
325+
326+
tokio::join!(listener, dialer);
324327
}
325328

326329
#[test]
327330
#[ignore] // TODO: for the moment unix addresses fail to parse
328331
fn larger_addr_denied() {
329-
let mut uds = UdsConfig::new();
332+
let mut uds = TokioUdsConfig::new();
330333

331334
let addr = "/unix//foo/bar".parse::<Multiaddr>().unwrap();
332335
assert!(uds.listen_on(ListenerId::next(), addr).is_err());

0 commit comments

Comments
 (0)