huskies: merge 1175 bug Flaky tests intermittently fail merge gates
This commit is contained in:
@@ -1690,8 +1690,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn find_free_port_returns_bindable_port() {
|
||||
let port = find_free_port(2200).expect("expected Some(port) in range 2200..2300");
|
||||
assert!((2200..2300).contains(&port));
|
||||
// Scan from an OS-assigned ephemeral port rather than a hardcoded low
|
||||
// port. Fixed ports like 2200 are also used as scan starts elsewhere
|
||||
// in production code and tests, so a second, independent bind on a
|
||||
// fixed port can race against those under parallel test execution.
|
||||
let reservation = std::net::TcpListener::bind(("127.0.0.1", 0)).unwrap();
|
||||
let start = reservation.local_addr().unwrap().port();
|
||||
drop(reservation);
|
||||
|
||||
let port = find_free_port(start).expect("expected Some(port) in scan range");
|
||||
assert!((start..start.saturating_add(100)).contains(&port));
|
||||
let listener = std::net::TcpListener::bind(("127.0.0.1", port));
|
||||
assert!(listener.is_ok(), "returned port {port} is not bindable");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user