Skip to content

Commit f65b5d0

Browse files
committed
Add unit test to connect to an unreachable address
Signed-off-by: Eval EXEC <[email protected]>
1 parent fca9e6e commit f65b5d0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/std/src/net/tcp/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ fn connect_error() {
4646
}
4747
}
4848

49+
#[test]
50+
fn connect_timeout_to_unreachable_address() {
51+
let now = Instant::now();
52+
match TcpStream::connect_timeout(&format!("1.1.1.1:9999").parse().unwrap(), Duration::MAX) {
53+
Ok(..) => panic!("connected to an unreachable address, this is impossible"),
54+
Err(e) => assert_eq!(e.kind(), ErrorKind::TimedOut),
55+
}
56+
57+
assert!(now.elapsed() > Duration::from_secs(20));
58+
}
59+
4960
#[test]
5061
fn connect_timeout_error() {
5162
let socket_addr = next_test_ip4();

0 commit comments

Comments
 (0)