From 43472ed221dbe8f1d7aab43d62043712c502e939 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Sat, 20 Jul 2024 10:22:25 +0200 Subject: [PATCH] frontend-utils: Use a loopback address for tests on Linux Turns out that some hosts will try to connect to the black hole address instead of failing instantaneously, so this patch replaces that address with a loopback address with an unlikely to be used port. --- frontend-utils/src/backends/navigator.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontend-utils/src/backends/navigator.rs b/frontend-utils/src/backends/navigator.rs index fbf546bd8..4796dd623 100644 --- a/frontend-utils/src/backends/navigator.rs +++ b/frontend-utils/src/backends/navigator.rs @@ -679,7 +679,17 @@ mod tests { #[macro_rules_attribute::apply(async_test)] async fn test_socket_fail() { - let addr = SocketAddr::from_str("[100::]:42").expect("black hole address"); + // We want to use here an address that will cause the connection to fail instantly. + // On Windows and macOS we use an IPv6 black hole address, + // as connections to 127.0.0.42:226 do not fail instantly. + // On Linux we try to use a loopback address with an unused port, + // because some hosts try connecting to the black hole address. + let addr = if cfg!(target_os = "linux") { + SocketAddr::from_str("127.0.0.42:226") + } else { + SocketAddr::from_str("[100::]:42") + } + .expect("test address"); let (_client_write, client_read) = connect_test_socket(addr, TIMEOUT, true); assert_next_socket_actions!(