huskies: merge 1175 bug Flaky tests intermittently fail merge gates

This commit is contained in:
Huskies Agent
2026-07-16 13:03:05 +00:00
parent 6a1ee8377d
commit 6f8a8ffd87
4 changed files with 48 additions and 4 deletions
@@ -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");
}