From a5aedf5dfe0d4b42b1f1c5a2169b3cb56d7bd1fa Mon Sep 17 00:00:00 2001 From: yushen Date: Wed, 25 Mar 2026 17:44:36 +0800 Subject: [PATCH] fix(test): gracefully skip DB tests when database is unreachable pgxpool.New is lazy and doesn't connect immediately. Add pool.Ping() after creation so CI environments without PostgreSQL skip cleanly instead of failing with os.Exit(1). Co-Authored-By: Claude Opus 4.6 (1M context) --- server/cmd/server/integration_test.go | 5 +++++ server/internal/handler/handler_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/server/cmd/server/integration_test.go b/server/cmd/server/integration_test.go index a879d3c1..a0cee2f3 100644 --- a/server/cmd/server/integration_test.go +++ b/server/cmd/server/integration_test.go @@ -49,6 +49,11 @@ func TestMain(m *testing.M) { fmt.Printf("Skipping integration tests: could not connect to database: %v\n", err) os.Exit(0) } + if err := pool.Ping(ctx); err != nil { + fmt.Printf("Skipping integration tests: database not reachable: %v\n", err) + pool.Close() + os.Exit(0) + } testPool = pool testUserID, testWorkspaceID, err = setupIntegrationTestFixture(ctx, pool) diff --git a/server/internal/handler/handler_test.go b/server/internal/handler/handler_test.go index db65ea19..3251482b 100644 --- a/server/internal/handler/handler_test.go +++ b/server/internal/handler/handler_test.go @@ -41,6 +41,11 @@ func TestMain(m *testing.M) { fmt.Printf("Skipping tests: could not connect to database: %v\n", err) os.Exit(0) } + if err := pool.Ping(ctx); err != nil { + fmt.Printf("Skipping tests: database not reachable: %v\n", err) + pool.Close() + os.Exit(0) + } queries := db.New(pool) hub := realtime.NewHub()