Skip to content

Commit

Permalink
Add unit test to connect to an unreachable address
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <execvy@gmail.com>
  • Loading branch information
eval-exec committed Jun 18, 2023
1 parent fca9e6e commit f65b5d0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions library/std/src/net/tcp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f65b5d0

Please sign in to comment.