Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: build
run: cargo build --workspace --features protobuf,grpc
- name: test
run: cargo test --workspace --features protobuf,grpc -- --skip cluster:: --skip cli::cli_cluster --skip cli::cli_benchmark --skip cli::cli_oneshot --skip cli::cli_connection
- name: test cluster crate
run: cargo test -p ember-cluster
- name: unit tests
run: cargo test --workspace --features protobuf,grpc --exclude ember-integration-tests
- name: integration tests
run: cargo test -p ember-integration-tests --test integration -- --test-threads=2

build:
name: build
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 31 additions & 1 deletion tests/integration/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::net::TcpListener;
use std::path::PathBuf;
use std::process::{Child, Command};
use std::sync::atomic::{AtomicU16, Ordering};
use std::time::Duration;

use bytes::{Bytes, BytesMut};
Expand Down Expand Up @@ -51,7 +52,13 @@ impl TestServer {
pub fn start_with(opts: ServerOptions) -> Self {
let binary = server_binary();

let port = find_free_port();
// cluster servers need 3 consecutive ports (data, gossip, raft).
// use deterministic allocation to avoid races and overlap.
let port = if opts.cluster_enabled {
allocate_ports(3)
} else {
find_free_port()
};

let mut cmd = Command::new(&binary);
cmd.arg("--port").arg(port.to_string());
Expand Down Expand Up @@ -322,6 +329,29 @@ impl TestClient {
}
}

/// Monotonic counter for deterministic port allocation, initialized
/// from the process ID to avoid collisions with stale servers from
/// previous test runs.
static PORT_COUNTER: AtomicU16 = AtomicU16::new(0);

/// Allocates a block of `count` consecutive ports guaranteed not to
/// overlap with any other test server in this process.
fn allocate_ports(count: u16) -> u16 {
// lazy-initialize from PID on first call so each test binary
// invocation gets a different starting range. The range 10000–40000
// keeps us well below the OS ephemeral range (49152+).
PORT_COUNTER
.compare_exchange(
0,
10_000 + (std::process::id() as u16 % 20_000),
Ordering::Relaxed,
Ordering::Relaxed,
)
.ok();

PORT_COUNTER.fetch_add(count, Ordering::Relaxed)
}

/// Finds a free TCP port by binding to port 0.
fn find_free_port() -> u16 {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
Expand Down
Loading