diff --git a/library/std/src/net/tcp/tests.rs b/library/std/src/net/tcp/tests.rs index 08ee451dfcd..4209d4b6342 100644 --- a/library/std/src/net/tcp/tests.rs +++ b/library/std/src/net/tcp/tests.rs @@ -46,6 +46,17 @@ fn connect_error() { } } +#[test] +fn connect_timeout_to_unreachable_address() { + let now = Instant::now(); + match TcpStream::connect_timeout(&format!("1.1.1.1:9999").parse().unwrap(), Duration::MAX) { + Ok(..) => panic!("connected to an unreachable address, this is impossible"), + Err(e) => assert_eq!(e.kind(), ErrorKind::TimedOut), + } + + assert!(now.elapsed() > Duration::from_secs(20)); +} + #[test] fn connect_timeout_error() { let socket_addr = next_test_ip4();