diff options
| author | Eval EXEC <execvy@gmail.com> | 2023-06-18 15:41:50 +0800 |
|---|---|---|
| committer | Eval EXEC <execvy@gmail.com> | 2023-06-18 15:59:25 +0800 |
| commit | f65b5d0ddf1ae0a551756424503c3cfe0e7ad8a6 (patch) | |
| tree | 1132f4064402e072b22ab7c57aa1954198284b7e | |
| parent | fca9e6e706d1b611c81c97ccdff8265f5f1ee638 (diff) | |
| download | rust-f65b5d0ddf1ae0a551756424503c3cfe0e7ad8a6.tar.gz rust-f65b5d0ddf1ae0a551756424503c3cfe0e7ad8a6.zip | |
Add unit test to connect to an unreachable address
Signed-off-by: Eval EXEC <execvy@gmail.com>
| -rw-r--r-- | library/std/src/net/tcp/tests.rs | 11 |
1 files changed, 11 insertions, 0 deletions
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 @@ -47,6 +47,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(); let result = TcpStream::connect_timeout(&socket_addr, Duration::MAX); |
