From 5aa9c783c3dfeae4d58fbb1b85f3bba62a40c9c7 Mon Sep 17 00:00:00 2001 From: Aleksey Shakhmatov Date: Mon, 23 Mar 2026 00:22:02 +0300 Subject: [PATCH] Fix NewTestCluster to skip tests when DB is unreachable pgxpool.NewWithConfig does not connect eagerly, so NewCluster succeeds even without a running database. Added a Ping check after cluster creation to reliably skip tests when the database cannot be reached. Co-Authored-By: Claude Opus 4.6 (1M context) --- dbxtest/dbxtest.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbxtest/dbxtest.go b/dbxtest/dbxtest.go index 1ffcc96..cc95609 100644 --- a/dbxtest/dbxtest.go +++ b/dbxtest/dbxtest.go @@ -46,6 +46,11 @@ func NewTestCluster(t testing.TB, opts ...dbx.Option) *dbx.Cluster { t.Skipf("dbxtest: cannot connect to test database: %v", err) } + if err := cluster.Ping(ctx); err != nil { + cluster.Close() + t.Skipf("dbxtest: cannot reach test database: %v", err) + } + t.Cleanup(func() { cluster.Close() })