diff --git a/crates/voelin-core/tests/gateway.rs b/crates/voelin-core/tests/gateway.rs index a623282..d4b254b 100644 --- a/crates/voelin-core/tests/gateway.rs +++ b/crates/voelin-core/tests/gateway.rs @@ -816,7 +816,16 @@ async fn not_found_proxy() -> String { #[tokio::test(flavor = "multi_thread")] async fn the_next_published_gateway_is_used_when_one_fails() { let proxy = not_found_proxy().await; - let closed = std::net::TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap().port(); + // A port that is taken and never listened on: connecting is refused at once, + // and no other test of this process can be given it meanwhile (one that was + // only free for a moment could be, the listeners of the others bind port 0). + let reserved = tokio::net::TcpSocket::new_v4().unwrap(); + reserved.bind("127.0.0.1:0".parse().unwrap()).unwrap(); + let closed = reserved.local_addr().unwrap().port(); + assert!( + tokio::net::TcpStream::connect(("127.0.0.1", closed)).await.is_err(), + "something listens on port {closed}" + ); let gw = FakeGateway::start().await; let path = temp_db("fallback"); let engine = Engine::start_with(Settings::in_memory(), History::open(&path).unwrap());