fix: probe a real postgres connection, not just TCP, for docker readiness
commit
af3c0e0fix: probe a real postgres connection, not just TCP, for docker readiness
A bare TCP connect can still succeed against postgres’s transient temp-instance listener during its post-initdb restart, so the previous TCP-only readiness check didn’t close the race: CI kept flaking with "error communicating with the server" on the very next real connection. Retry an actual PostgresRefStore::connect instead, in every duplicated harness that starts its own container.
Assisted-by: Claude:claude-sonnet-5
Reviews
No reviews of this commit yet — record a verdict below.
Start a review
crates/effect-dispatcher/tests/postgres_queue.rs
@@ -126,24 +126,24 @@
.trim()
.to_owned();
+ let url = format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres");
+
// `pg_isready` above checks the container's internal socket, which can
- // report ready slightly before the published TCP port is actually
- // reachable from the host. Confirm a real connection before handing the
- // URL to callers.
- if !wait_for_tcp(&format!("127.0.0.1:{port}")) {
- eprintln!("effect-dispatcher postgres_queue: postgres port never became reachable");
+ // report ready before the postgres entrypoint's post-initdb restart
+ // finishes — a raw TCP connect can succeed against that transient
+ // listener too. Only a real protocol-level connection confirms the
+ // final server is actually up.
+ if !wait_for_postgres_ready(&url) {
+ eprintln!("effect-dispatcher postgres_queue: postgres never became reachable");
return None;
}
- Some(TestPostgres::Docker {
- url: format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres"),
- container_id,
- })
+ Some(TestPostgres::Docker { url, container_id })
}
-fn wait_for_tcp(addr: &str) -> bool {
+fn wait_for_postgres_ready(url: &str) -> bool {
for _ in 0..40 {
- if std::net::TcpStream::connect(addr).is_ok() {
+ if PostgresRefStore::connect(url, "readiness-probe").is_ok() {
return true;
}
std::thread::sleep(Duration::from_millis(250));
crates/git-ents-server/tests/hydrate.rs
@@ -134,24 +134,24 @@
.trim()
.to_owned();
+ let url = format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres");
+
// `pg_isready` above checks the container's internal socket, which can
- // report ready slightly before the published TCP port is actually
- // reachable from the host. Confirm a real connection before handing the
- // URL to callers.
- if !wait_for_tcp(&format!("127.0.0.1:{port}")) {
- eprintln!("git-ents-server hydrate test: postgres port never became reachable");
+ // report ready before the postgres entrypoint's post-initdb restart
+ // finishes — a raw TCP connect can succeed against that transient
+ // listener too. Only a real protocol-level connection confirms the
+ // final server is actually up.
+ if !wait_for_postgres_ready(&url) {
+ eprintln!("git-ents-server hydrate test: postgres never became reachable");
return None;
}
- Some(TestPostgres::Docker {
- url: format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres"),
- container_id,
- })
+ Some(TestPostgres::Docker { url, container_id })
}
-fn wait_for_tcp(addr: &str) -> bool {
+fn wait_for_postgres_ready(url: &str) -> bool {
for _ in 0..40 {
- if std::net::TcpStream::connect(addr).is_ok() {
+ if PostgresRefStore::connect(url, "readiness-probe").is_ok() {
return true;
}
std::thread::sleep(Duration::from_millis(250));
crates/refstore-postgres/tests/conformance.rs
@@ -119,24 +119,24 @@
.trim()
.to_owned();
+ let url = format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres");
+
// `pg_isready` above checks the container's internal socket, which can
- // report ready slightly before the published TCP port is actually
- // reachable from the host. Confirm a real connection before handing the
- // URL to callers.
- if !wait_for_tcp(&format!("127.0.0.1:{port}")) {
- eprintln!("refstore-postgres tests: postgres port never became reachable");
+ // report ready before the postgres entrypoint's post-initdb restart
+ // finishes — a raw TCP connect can succeed against that transient
+ // listener too. Only a real protocol-level connection confirms the
+ // final server is actually up.
+ if !wait_for_postgres_ready(&url) {
+ eprintln!("refstore-postgres tests: postgres never became reachable");
return None;
}
- Some(TestPostgres::Docker {
- url: format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres"),
- container_id,
- })
+ Some(TestPostgres::Docker { url, container_id })
}
-fn wait_for_tcp(addr: &str) -> bool {
+fn wait_for_postgres_ready(url: &str) -> bool {
for _ in 0..40 {
- if std::net::TcpStream::connect(addr).is_ok() {
+ if PostgresRefStore::connect(url, "readiness-probe").is_ok() {
return true;
}
std::thread::sleep(Duration::from_millis(250));
crates/refstore-postgres/tests/odb_ws5_conformance.rs
@@ -121,24 +121,24 @@
.trim()
.to_owned();
+ let url = format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres");
+
// `pg_isready` above checks the container's internal socket, which can
- // report ready slightly before the published TCP port is actually
- // reachable from the host. Confirm a real connection before handing the
- // URL to callers.
- if !wait_for_tcp(&format!("127.0.0.1:{port}")) {
- eprintln!("refstore-postgres odb_ws5_conformance: postgres port never became reachable");
+ // report ready before the postgres entrypoint's post-initdb restart
+ // finishes — a raw TCP connect can succeed against that transient
+ // listener too. Only a real protocol-level connection confirms the
+ // final server is actually up.
+ if !wait_for_postgres_ready(&url) {
+ eprintln!("refstore-postgres odb_ws5_conformance: postgres never became reachable");
return None;
}
- Some(TestPostgres::Docker {
- url: format!("host=127.0.0.1 port={port} user=postgres password=postgres dbname=postgres"),
- container_id,
- })
+ Some(TestPostgres::Docker { url, container_id })
}
-fn wait_for_tcp(addr: &str) -> bool {
+fn wait_for_postgres_ready(url: &str) -> bool {
for _ in 0..40 {
- if std::net::TcpStream::connect(addr).is_ok() {
+ if PostgresRefStore::connect(url, "readiness-probe").is_ok() {
return true;
}
std::thread::sleep(Duration::from_millis(250));