diff --git a/README.md b/README.md index 10270e13..76932a6d 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,19 @@ man soroban-debug man soroban-debug-run ``` +## CI / Developer Makefile Targets + +For sandbox or restricted CI environments where socket bind may fail, use: + +```bash +make ci-sandbox +``` + +This target runs formatting, lint, non-network tests, VS Code tests, and man-page checks while skipping loopback TCP network-dependent tests. + +- `make test-rust-sandbox`: Run Rust tests excluding `parity_dap_server*` tests. +- `make test-rust-network`: Run only network-dependent parity server tests. + ## Quick Start ### Basic Usage diff --git a/tests/network/mod.rs b/tests/network/mod.rs index 0d61c1f0..b4ab0866 100644 --- a/tests/network/mod.rs +++ b/tests/network/mod.rs @@ -28,3 +28,11 @@ pub fn can_bind_loopback() -> bool { } } } + +/// Allocate an ephemeral available port by binding to 0 and reading the assigned value. +/// The temporary listener is dropped after determining the port so it can be re-used. +/// This reduces brittle fixed-port usage in integration tests. +pub fn allocate_ephemeral_port() -> Option { + let listener = TcpListener::bind("127.0.0.1:0").ok()?; + listener.local_addr().ok().map(|addr| addr.port()) +} diff --git a/tests/parity_tests.rs b/tests/parity_tests.rs index ef21c52f..7201217a 100644 --- a/tests/parity_tests.rs +++ b/tests/parity_tests.rs @@ -295,7 +295,7 @@ fn parity_dap_server_starts_and_accepts_connection() { use std::net::TcpStream; use std::time::Duration; - let port = 19_230u16; + let port = network::allocate_ephemeral_port().expect("Failed to allocate ephemeral port"); let token = "parity-test-token-ok"; let mut server = std::process::Command::new(env!("CARGO_BIN_EXE_soroban-debug")) @@ -370,7 +370,7 @@ fn parity_dap_server_rejects_invalid_token() { use std::net::TcpStream; use std::time::Duration; - let port = 19_231u16; + let port = network::allocate_ephemeral_port().expect("Failed to allocate ephemeral port"); let real_token = "real-parity-token"; let wrong_token = "wrong-parity-token"; diff --git a/tests/remote_run_tests.rs b/tests/remote_run_tests.rs index 2f86e874..cbbab453 100644 --- a/tests/remote_run_tests.rs +++ b/tests/remote_run_tests.rs @@ -56,13 +56,16 @@ fn test_remote_run_execution() { wasm_path } + // Allocate an ephemeral free port for this test. + let port = network::allocate_ephemeral_port().expect("Failed to allocate ephemeral port"); + // Start server in background let mut server_cmd = StdCommand::new(assert_cmd::cargo::cargo_bin!("soroban-debug")); let mut server_child = server_cmd .arg("server") .arg("--port") - .arg("9245") + .arg(port.to_string()) .arg("--token") .arg("secret") .spawn() @@ -76,7 +79,7 @@ fn test_remote_run_execution() { ping_cmd .arg("run") .arg("--remote") - .arg("127.0.0.1:9245") + .arg(format!("127.0.0.1:{}", port)) .arg("--token") .arg("secret") .assert() @@ -90,7 +93,7 @@ fn test_remote_run_execution() { let assert = client_cmd .arg("run") .arg("--remote") - .arg("127.0.0.1:9245") + .arg(format!("127.0.0.1:{}", port)) .arg("--token") .arg("secret") .arg("--contract")