Skip to content

Commit 551986e

Browse files
committed
fix start server listen
1 parent 5af3196 commit 551986e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/src/http/stream.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,14 @@ impl AsyncWrite for Stream {
121121
async fn test_connect() {
122122
crate::tests::start_server(30000).await;
123123
let stream = Stream::connect(&Url::from("http://127.0.0.1:30000/get"), Duration::from_secs(2)).await;
124+
if let Err(error) = stream.as_ref() {
125+
println!("{:?}", error);
126+
}
124127
assert!(stream.is_ok());
125128
let stream = Stream::connect(&Url::from("http://localhost:30000/get"), Duration::from_secs(2)).await;
129+
if let Err(error) = stream.as_ref() {
130+
println!("{:?}", error);
131+
}
126132
assert!(stream.is_ok());
127133
let stream = Stream::connect(&Url::from("http://localhost:88/get"), Duration::from_secs(2)).await;
128134
assert!(stream.is_err());

lib/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub mod tests {
3737
use serde_json::json;
3838
use serde_json::Value;
3939
use std::collections::HashMap;
40+
use std::net::IpAddr;
41+
use std::net::Ipv6Addr;
42+
use std::net::SocketAddr;
4043

4144
pub async fn start_server(port: u16) {
4245
let router = Router::new()
@@ -45,8 +48,8 @@ pub mod tests {
4548
.route("/json", post(handle_json))
4649
.route("/form", post(handle_form))
4750
.route("/multipart", post(handle_multipart));
48-
49-
let listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await.unwrap();
51+
let addr = &SocketAddr::new(IpAddr::from(Ipv6Addr::UNSPECIFIED), port);
52+
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
5053
tokio::spawn(async move {
5154
axum::serve(listener, router).await.unwrap();
5255
});

0 commit comments

Comments
 (0)