From ed33e9a7fd85b23918a8545d7dc1a8aacdaee4f1 Mon Sep 17 00:00:00 2001 From: kant Date: Tue, 10 Feb 2026 12:57:44 -0800 Subject: [PATCH] fix: use robust wait strategy for postgres testcontainers Replace wait.ForListeningPort with wait.ForAll combining ForLog and ForListeningPort. PostgreSQL opens the TCP port before initialization completes, causing "connection reset by peer" errors. The log message appears twice (once during initdb, once after restart), so WithOccurrence(2) ensures full readiness before tests connect. --- bridge/standard/pkg/store/store_test.go | 8 +++++++- oracle/pkg/store/store_test.go | 8 +++++++- tools/preconf-rpc/store/store_test.go | 7 ++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bridge/standard/pkg/store/store_test.go b/bridge/standard/pkg/store/store_test.go index 7a1c96b4b..961583418 100644 --- a/bridge/standard/pkg/store/store_test.go +++ b/bridge/standard/pkg/store/store_test.go @@ -6,6 +6,7 @@ import ( "fmt" "math/big" "testing" + "time" "github.com/ethereum/go-ethereum/common" "github.com/primev/mev-commit/bridge/standard/pkg/store" @@ -33,7 +34,12 @@ func TestStore(t *testing.T) { "POSTGRES_USER": "user", "POSTGRES_PASSWORD": "password", }, - WaitingFor: wait.ForListeningPort("5432/tcp"), + WaitingFor: wait.ForAll( + wait.ForLog("database system is ready to accept connections"). + WithOccurrence(2). + WithStartupTimeout(60*time.Second), + wait.ForListeningPort("5432/tcp"), + ), } // Start the PostgreSQL container diff --git a/oracle/pkg/store/store_test.go b/oracle/pkg/store/store_test.go index 6ae63a4f1..3297b1852 100644 --- a/oracle/pkg/store/store_test.go +++ b/oracle/pkg/store/store_test.go @@ -6,6 +6,7 @@ import ( "fmt" "math/big" "testing" + "time" "github.com/ethereum/go-ethereum/common" "github.com/google/go-cmp/cmp" @@ -46,7 +47,12 @@ func TestStore(t *testing.T) { "POSTGRES_USER": "user", "POSTGRES_PASSWORD": "password", }, - WaitingFor: wait.ForListeningPort("5432/tcp"), + WaitingFor: wait.ForAll( + wait.ForLog("database system is ready to accept connections"). + WithOccurrence(2). + WithStartupTimeout(60*time.Second), + wait.ForListeningPort("5432/tcp"), + ), } // Start the PostgreSQL container diff --git a/tools/preconf-rpc/store/store_test.go b/tools/preconf-rpc/store/store_test.go index 8773410e3..8f4464527 100644 --- a/tools/preconf-rpc/store/store_test.go +++ b/tools/preconf-rpc/store/store_test.go @@ -33,7 +33,12 @@ func TestStore(t *testing.T) { "POSTGRES_USER": "user", "POSTGRES_PASSWORD": "password", }, - WaitingFor: wait.ForListeningPort("5432/tcp"), + WaitingFor: wait.ForAll( + wait.ForLog("database system is ready to accept connections"). + WithOccurrence(2). + WithStartupTimeout(60*time.Second), + wait.ForListeningPort("5432/tcp"), + ), } // Start the PostgreSQL container