Fix NewTestCluster to skip tests when DB is unreachable
All checks were successful
CI / test (push) Successful in 30s

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) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 00:22:02 +03:00
parent 2c9af28548
commit 5aa9c783c3

View File

@@ -46,6 +46,11 @@ func NewTestCluster(t testing.TB, opts ...dbx.Option) *dbx.Cluster {
t.Skipf("dbxtest: cannot connect to test database: %v", err) 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() { t.Cleanup(func() {
cluster.Close() cluster.Close()
}) })