From 7d3453668a4621e8fabd7e4034e40f86b711f050 Mon Sep 17 00:00:00 2001 From: Yilin Chen Date: Sat, 27 Jul 2024 22:38:00 +0800 Subject: [PATCH] Replace async-std with smol in tests Signed-off-by: Yilin Chen --- Cargo.toml | 3 +-- src/io/compat.rs | 2 +- tests/common/futures_utils.rs | 13 +++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8968d42..24323b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,5 +41,4 @@ futures-executor = "0.3" futures-util = { version = "0.3", default-features = false, features = ["io"] } tokio = { version = "1.0", features = ["io-util", "rt-multi-thread", "net"] } once_cell = "1.2.0" -hyper = "0.14" -async-std = "1.12.0" +smol = "2.0.0" diff --git a/src/io/compat.rs b/src/io/compat.rs index e283f86..cac7f66 100644 --- a/src/io/compat.rs +++ b/src/io/compat.rs @@ -5,7 +5,7 @@ mod futures; /// /// Example: /// ```no_run -/// use async_std::os::unix::net::UnixStream; +/// use smol::net::unix::UnixStream; /// use tokio_socks::{io::Compat, tcp::Socks5Stream}; /// let socket = Compat::new(UnixStream::connect(proxy_addr) /// .await diff --git a/tests/common/futures_utils.rs b/tests/common/futures_utils.rs index 7e8f523..06d866f 100644 --- a/tests/common/futures_utils.rs +++ b/tests/common/futures_utils.rs @@ -1,7 +1,7 @@ use super::*; -use async_std::{net::TcpListener, os::unix::net::UnixStream}; use futures_util::{io::copy, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; use once_cell::sync::OnceCell; +use smol::net::{unix::UnixStream, TcpListener}; use std::{ future::Future, io::{Read, Write}, @@ -19,10 +19,11 @@ pub async fn echo_server() -> Result<()> { let listener = TcpListener::bind(&SocketAddr::from(([0, 0, 0, 0], 10007))).await?; loop { let (stream, _) = listener.accept().await?; - async_std::task::spawn(async move { + smol::spawn(async move { let (mut reader, mut writer) = stream.split(); copy(&mut reader, &mut writer).await.unwrap(); - }); + }) + .detach(); } } @@ -69,19 +70,19 @@ impl Runtime { F: Future + Send + 'static, T: Send + 'static, { - async_std::task::spawn(future); + smol::spawn(future).detach(); } pub fn block_on(&self, future: F) -> T where F: Future { - async_std::task::block_on(future) + smol::block_on(future) } } pub fn runtime() -> &'static Mutex { static RUNTIME: OnceCell> = OnceCell::new(); RUNTIME.get_or_init(|| { - async_std::task::spawn(async { echo_server().await.expect("Unable to bind") }); + smol::spawn(async { echo_server().await.expect("Unable to bind") }).detach(); Mutex::new(Runtime) }) }