diff --git a/src/cli/proxy.rs b/src/cli/proxy.rs index 212656feac..bfefe31a8f 100644 --- a/src/cli/proxy.rs +++ b/src/cli/proxy.rs @@ -269,7 +269,8 @@ mod tests { let mut t = TestHelper::default(); let endpoint = t.open_socket_and_recv_single_packet().await; - let local_addr = available_addr(&AddressType::Random).await; + let mut local_addr = available_addr(&AddressType::Ipv6).await; + crate::test_utils::map_addr_to_localhost(&mut local_addr); let proxy = crate::cli::Proxy { port: local_addr.port(), ..<_>::default() @@ -278,14 +279,16 @@ mod tests { config.clusters.modify(|clusters| { clusters.insert_default( [Endpoint::new( - endpoint.socket.local_ipv4_addr().unwrap().into(), + endpoint.socket.local_ipv6_addr().unwrap().into(), )] .into(), ); }); t.run_server(config, proxy, None); + tokio::time::sleep(std::time::Duration::from_millis(100)).await; let msg = "hello"; + tracing::debug!(%local_addr, "sending packet"); endpoint .socket .send_to(msg.as_bytes(), &local_addr) diff --git a/src/proxy/sessions.rs b/src/proxy/sessions.rs index b12d1ac091..97a726f389 100644 --- a/src/proxy/sessions.rs +++ b/src/proxy/sessions.rs @@ -658,21 +658,13 @@ mod tests { let mut t = TestHelper::default(); let dest = t.run_echo_server(&AddressType::Ipv6).await; let mut dest = dest.to_socket_addr().await.unwrap(); + crate::test_utils::map_addr_to_localhost(&mut dest); let source = available_addr(&AddressType::Ipv6).await; let socket = tokio::net::UdpSocket::bind(source).await.unwrap(); let mut source = socket.local_addr().unwrap(); + crate::test_utils::map_addr_to_localhost(&mut source); let (pool, _sender) = new_pool(None).await; - match &mut dest { - std::net::SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST), - std::net::SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST), - }; - - match &mut source { - std::net::SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST), - std::net::SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST), - }; - let key: SessionKey = (source, dest).into(); let msg = b"helloworld"; diff --git a/src/test_utils.rs b/src/test_utils.rs index b33540b7cf..b61e44c5a8 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -333,13 +333,15 @@ where pub async fn map_to_localhost(address: &mut EndpointAddress) { let mut socket_addr = address.to_socket_addr().await.unwrap(); + map_addr_to_localhost(&mut socket_addr); + *address = socket_addr.into(); +} - match &mut socket_addr { +pub fn map_addr_to_localhost(address: &mut SocketAddr) { + match address { SocketAddr::V4(addr) => addr.set_ip(std::net::Ipv4Addr::LOCALHOST), SocketAddr::V6(addr) => addr.set_ip(std::net::Ipv6Addr::LOCALHOST), } - - *address = socket_addr.into(); } /// Opens a new socket bound to an ephemeral port diff --git a/tests/capture.rs b/tests/capture.rs index 96379e940f..344cdefba4 100644 --- a/tests/capture.rs +++ b/tests/capture.rs @@ -31,7 +31,8 @@ use quilkin::{ #[tokio::test] async fn token_router() { let mut t = TestHelper::default(); - let echo = t.run_echo_server(&AddressType::Random).await; + let mut echo = t.run_echo_server(&AddressType::Random).await; + quilkin::test_utils::map_to_localhost(&mut echo).await; let server_port = 12348; let server_proxy = quilkin::cli::Proxy { port: server_port, diff --git a/tests/token_router.rs b/tests/token_router.rs index 458a6e0840..2e6f4edfcd 100644 --- a/tests/token_router.rs +++ b/tests/token_router.rs @@ -30,8 +30,10 @@ use quilkin::{ /// since they work in concert together. #[tokio::test] async fn token_router() { + quilkin::test_utils::enable_log("quilkin=trace"); let mut t = TestHelper::default(); - let echo = t.run_echo_server(&AddressType::Ipv6).await; + let mut echo = t.run_echo_server(&AddressType::Ipv6).await; + quilkin::test_utils::map_to_localhost(&mut echo).await; let capture_yaml = " suffix: