Add unit test to connect to an unreachable address

Signed-off-by: Eval EXEC <execvy@gmail.com>
This commit is contained in:
Eval EXEC 2023-06-18 15:41:50 +08:00
parent fca9e6e706
commit f65b5d0ddf
No known key found for this signature in database
GPG Key ID: 0F0272C0D3AC91F7

View File

@ -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();