Skip to content

Commit 6f00d5c

Browse files
authored
fix(e2e): reserve distinct corporate proxy fixture ports (ai-openshell#3761)
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 7a4da31 commit 6f00d5c

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎e2e/rust/tests/vm_corporate_proxy.rs‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
3131
use std::fmt::Write as _;
3232
use std::io::Write as _;
33+
use std::net::{Ipv4Addr, SocketAddrV4, TcpListener};
3334
use std::path::PathBuf;
3435
use std::time::Duration;
3536

3637
use openshell_e2e::harness::cli::wait_for_healthy;
3738
use openshell_e2e::harness::gateway::ManagedGateway;
3839
use openshell_e2e::harness::host_process::HostPythonFixture;
39-
use openshell_e2e::harness::port::find_free_port;
4040
use openshell_e2e::harness::sandbox::SandboxGuard;
4141
use serial_test::serial;
4242
use tempfile::NamedTempFile;
@@ -63,11 +63,29 @@ struct FixturePorts {
6363

6464
impl FixturePorts {
6565
fn pick() -> Self {
66+
// Keep all four listeners bound while allocating ports. Calling the
67+
// single-port helper repeatedly can return the same released port,
68+
// making an allowed CONNECT look like one to the denied fixture.
69+
let listeners: Vec<_> = (0..4)
70+
.map(|_| {
71+
TcpListener::bind(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0))
72+
.expect("reserve corporate proxy fixture port")
73+
})
74+
.collect();
75+
let ports: Vec<_> = listeners
76+
.iter()
77+
.map(|listener| {
78+
listener
79+
.local_addr()
80+
.expect("fixture listener address")
81+
.port()
82+
})
83+
.collect();
6684
Self {
67-
proxy: find_free_port(),
68-
allowed: find_free_port(),
69-
denied: find_free_port(),
70-
bypass: find_free_port(),
85+
proxy: ports[0],
86+
allowed: ports[1],
87+
denied: ports[2],
88+
bypass: ports[3],
7189
}
7290
}
7391
}

0 commit comments

Comments
 (0)