Skip to content

Commit

Permalink
Replace async-std with smol in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
  • Loading branch information
sticnarf committed Jul 27, 2024
1 parent 7c547cb commit 7d34536
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/io/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions tests/common/futures_utils.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -69,19 +70,19 @@ impl Runtime {
F: Future<Output = T> + Send + 'static,
T: Send + 'static,
{
async_std::task::spawn(future);
smol::spawn(future).detach();
}

pub fn block_on<F, T>(&self, future: F) -> T
where F: Future<Output = T> {
async_std::task::block_on(future)
smol::block_on(future)
}
}

pub fn runtime() -> &'static Mutex<Runtime> {
static RUNTIME: OnceCell<Mutex<Runtime>> = 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)
})
}
Expand Down

0 comments on commit 7d34536

Please sign in to comment.