File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,26 @@ fn connect_error() {
4646 }
4747}
4848
49+ #[ test]
50+ fn connect_timeout_error ( ) {
51+ let socket_addr = next_test_ip4 ( ) ;
52+ let result = TcpStream :: connect_timeout ( & socket_addr, Duration :: MAX ) ;
53+ assert ! ( !matches!( result, Err ( e) if e. kind( ) == ErrorKind :: TimedOut ) ) ;
54+
55+ let _listener = TcpListener :: bind ( & socket_addr) . unwrap ( ) ;
56+ assert ! ( TcpStream :: connect_timeout( & socket_addr, Duration :: MAX ) . is_ok( ) ) ;
57+ }
58+
59+ #[ test]
60+ fn connect_timeout_ok_bind ( ) {
61+ let listener = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ; // :0 picks some free port
62+ let port = listener. local_addr ( ) . unwrap ( ) . port ( ) ; // obtain the port it picked
63+ assert ! (
64+ TcpStream :: connect_timeout( & format!( "127.0.0.1:{port}" ) . parse( ) . unwrap( ) , Duration :: MAX )
65+ . is_ok( )
66+ ) ;
67+ }
68+
4969#[ test]
5070fn listen_localhost ( ) {
5171 let socket_addr = next_test_ip4 ( ) ;
You can’t perform that action at this time.
0 commit comments