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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ release:
cargo build --release

test:
cargo test --workspace --features protobuf,grpc
cargo test --workspace --features protobuf,grpc -- --test-threads=1

fmt:
cargo fmt --all
Expand Down
29 changes: 27 additions & 2 deletions tests/integration/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ impl TestServer {
panic!("failed to spawn ember-server at {}: {e}", binary.display())
});

// wait for the server to accept TCP connections
// wait until the server is ready to handle commands (not just TCP open)
let deadline = std::time::Instant::now() + Duration::from_secs(5);
loop {
if std::time::Instant::now() > deadline {
panic!("ember-server failed to start within 5 seconds on port {port}");
}
if std::net::TcpStream::connect(format!("127.0.0.1:{port}")).is_ok() {
if Self::ping_ready_sync(port) {
break;
}
std::thread::sleep(Duration::from_millis(50));
Expand Down Expand Up @@ -220,6 +220,31 @@ impl TestServer {
}
}

/// Sends PING and returns true if the server responds with PONG.
/// Used as a readiness probe — stronger than a bare TCP connect check
/// because it confirms the command dispatcher is running.
fn ping_ready_sync(port: u16) -> bool {
use std::io::{Read, Write};

let Ok(mut stream) = std::net::TcpStream::connect(format!("127.0.0.1:{port}")) else {
return false;
};
stream
.set_read_timeout(Some(Duration::from_millis(500)))
.ok();
if stream.write_all(b"*1\r\n$4\r\nPING\r\n").is_err() {
return false;
}
let mut buf = vec![0u8; 128];
match stream.read(&mut buf) {
Ok(n) if n > 0 => {
let r = &buf[..n];
r.starts_with(b"+PONG") || r.starts_with(b"$4\r\nPONG")
}
_ => false,
}
}

/// Connects a test client to this server.
pub async fn connect(&self) -> TestClient {
TestClient::connect(self.port).await
Expand Down