test(infrastructure): Configure pgxpool with max_conns=1

Fix database connection exhaustion in tests by setting max_conns=1
when creating pgxpool via pgxpool.ParseConfig().

- Update setupTestServer() in test_helpers.go
- Update setupSyncTestDB() in sync_integration_test.go

This reduces per-test connection usage from 4 to 1, keeping total
connections well under PostgreSQL's default max_connections=100.

78 tests × 1 connection = 78 connections (down from 312 potential)

Fixes test failures: "FATAL: sorry, too many clients already"

See PROJECT_GUIDELINES.md Testing section for details.
This commit is contained in:
2026-02-11 10:37:38 -05:00
parent 61115bc8cd
commit 891209b4bd
10 changed files with 124 additions and 478 deletions
+6 -1
View File
@@ -309,7 +309,12 @@ func setupTestServer(t *testing.T) *TestServerSetup {
cfg.RequestsPerMinute = 1000
// Connect to test database using the same method as main application
dbPool, err := pgxpool.New(context.Background(), cfg.DatabaseURL())
// Use max_conns=1 to prevent connection pool exhaustion during test runs
// (78 tests × 1 connection = 78 connections, well under PostgreSQL's 100 default max_connections)
dbConfig, err := pgxpool.ParseConfig(cfg.DatabaseURL())
require.NoError(t, err, "Failed to parse database URL")
dbConfig.MaxConns = 1
dbPool, err := pgxpool.NewWithConfig(context.Background(), dbConfig)
require.NoError(t, err, "Failed to connect to test database")
queries := database.New(dbPool)