From 37962e6a5eff289b35605b42a6c5363b9a2c58ee Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Wed, 4 Dec 2024 00:08:52 +0800 Subject: [PATCH] chore: udp_tunnel test udp server listen on a random port --- tests/tunnel.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/tunnel.rs b/tests/tunnel.rs index 508d7c1ae3b2..435b7ac9d386 100644 --- a/tests/tunnel.rs +++ b/tests/tunnel.rs @@ -89,11 +89,13 @@ async fn tcp_tunnel() { async fn udp_tunnel() { let _ = env_logger::try_init(); - // A UDP echo server - tokio::spawn(async { - let socket = UdpSocket::bind("127.0.0.1:9230").await.unwrap(); + let socket = UdpSocket::bind("127.0.0.1:0").await.unwrap(); + let socket_local_addr = socket.local_addr().unwrap(); + let echo_server_port = socket_local_addr.port(); - debug!("UDP echo server listening on 127.0.0.1:9230"); + // A UDP echo server + tokio::spawn(async move { + debug!("UDP echo server listening on {socket_local_addr}"); let mut buffer = [0u8; 65536]; loop { @@ -115,7 +117,7 @@ async fn udp_tunnel() { "local_address": "127.0.0.1", "protocol": "tunnel", "forward_address": "127.0.0.1", - "forward_port": 9230 + "forward_port": {echo_server_port} }} ], "server": "127.0.0.1",