fix: retry the docker postgres connection in the dispatcher queue test
commit
c31c1f7fix: retry the docker postgres connection in the dispatcher queue test
pg_isready checks the container’s internal socket and can report ready slightly before the published TCP port is reachable, which was flaking CI’s dispatcher_sql_claims_across_repos_requeues_stale_and_completes test with "error communicating with the server" on the first connect.
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
@@ -18,6 +18,7 @@
#![allow(
clippy::unwrap_used,
clippy::expect_used,
+ clippy::panic,
reason = "test harness and assertions, not application code"
)]
@@ -132,6 +133,27 @@
})
}
+/// `pg_isready` (used by [`start_docker_postgres`]) checks the container's
+/// internal socket, which can report ready slightly before the published
+/// TCP port is actually reachable. Retry the first real connection instead
+/// of failing on that race.
+fn connect_with_retry(url: &str, repo: String) -> PostgresRefStore {
+ let mut last_err = None;
+ for _ in 0..20 {
+ match PostgresRefStore::connect(url, repo.clone()) {
+ Ok(store) => return store,
+ Err(err) => {
+ last_err = Some(err);
+ std::thread::sleep(Duration::from_millis(250));
+ }
+ }
+ }
+ panic!(
+ "connect: {:?}",
+ last_err.expect("at least one connection attempt")
+ )
+}
+
#[test]
fn dispatcher_sql_claims_across_repos_requeues_stale_and_completes() {
let Some(pg) = test_postgres() else {
@@ -143,8 +165,8 @@
};
let repo_a = format!("dispatch-a-{}", uuid::Uuid::new_v4());
let repo_b = format!("dispatch-b-{}", uuid::Uuid::new_v4());
- let store_a = PostgresRefStore::connect(pg.url(), repo_a.clone()).expect("connect a");
- let store_b = PostgresRefStore::connect(pg.url(), repo_b.clone()).expect("connect b");
+ let store_a = connect_with_retry(pg.url(), repo_a.clone());
+ let store_b = connect_with_retry(pg.url(), repo_b.clone());
let a_id: i64 = store_a
.enqueue_effect("payload-a")
.expect("enqueue a")