Skip to content

Commit

Permalink
Fix concurrent invocations of preview2_tcp_bind test
Browse files Browse the repository at this point in the history
When binding a specific port allow `AddressInUse` errors to be returned
in case the test is being concurrently run.
  • Loading branch information
alexcrichton committed Oct 23, 2023
1 parent 9d8ca82 commit d3caf2d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/test-programs/src/bin/preview2_tcp_bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ fn test_tcp_bind_specific_port(net: &Network, ip: IpAddress) {
let bind_addr = IpSocketAddress::new(ip, PORT);

let sock = TcpSocket::new(ip.family()).unwrap();
sock.blocking_bind(net, bind_addr).unwrap();

let bound_addr = sock.local_address().unwrap();

assert_eq!(bind_addr.ip(), bound_addr.ip());
assert_eq!(bind_addr.port(), bound_addr.port());
match sock.blocking_bind(net, bind_addr) {
Ok(()) => {
let bound_addr = sock.local_address().unwrap();

assert_eq!(bind_addr.ip(), bound_addr.ip());
assert_eq!(bind_addr.port(), bound_addr.port());
}
Err(ErrorCode::AddressInUse) => {}
Err(e) => panic!("error: {e}"),
}
}

/// Two sockets may not be actively bound to the same address at the same time.
Expand Down

0 comments on commit d3caf2d

Please sign in to comment.