Skip to content

Commit baaa6ff

Browse files
committed
test: Support configurable base port for concurrent test processes
Read LDK_NODE_TEST_BASE_PORT env var to offset the listening port range, avoiding collisions when multiple test processes run simultaneously. Assign base ports 20000, 21000, 22000 to the three concurrent processes in the stress-test CI job. AI tools were used in preparing this commit.
1 parent 6de9312 commit baaa6ff

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
for i in $(seq 1 5); do
129129
echo "=== Iteration $i (shard ${{ matrix.shard }}) ==="
130130
for j in 1 2 3; do
131-
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test --test integration_tests_rust -- --nocapture > /tmp/stress-${j}.log 2>&1 &
131+
LDK_NODE_TEST_BASE_PORT=$((20000 + (j - 1) * 1000)) RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test --test integration_tests_rust -- --nocapture > /tmp/stress-${j}.log 2>&1 &
132132
pids[${j}]=$!
133133
done
134134
for j in 1 2 3; do

tests/common/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::env;
1515
use std::future::Future;
1616
use std::path::PathBuf;
1717
use std::sync::atomic::{AtomicU16, Ordering};
18-
use std::sync::{Arc, RwLock};
18+
use std::sync::{Arc, LazyLock, RwLock};
1919
use std::time::Duration;
2020

2121
use bitcoin::hashes::hex::FromHex;
@@ -274,7 +274,10 @@ pub(crate) fn random_storage_path() -> PathBuf {
274274
temp_path
275275
}
276276

277-
static NEXT_PORT: AtomicU16 = AtomicU16::new(20000);
277+
static BASE_PORT: LazyLock<u16> = LazyLock::new(|| {
278+
env::var("LDK_NODE_TEST_BASE_PORT").ok().and_then(|v| v.parse().ok()).unwrap_or(20000)
279+
});
280+
static NEXT_PORT: LazyLock<AtomicU16> = LazyLock::new(|| AtomicU16::new(*BASE_PORT));
278281

279282
pub(crate) fn generate_listening_addresses() -> Vec<SocketAddress> {
280283
let port = NEXT_PORT.fetch_add(2, Ordering::Relaxed);

0 commit comments

Comments
 (0)