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:
@@ -18,7 +18,11 @@ func setupSyncTestDB(t *testing.T) *database.Queries {
|
||||
ctx := context.Background()
|
||||
|
||||
dbURL := "postgresql://postgres:postgres@db:5432/bookhoard?sslmode=disable"
|
||||
dbPool, err := pgxpool.New(ctx, dbURL)
|
||||
// Use max_conns=1 to prevent connection pool exhaustion during test runs
|
||||
dbConfig, err := pgxpool.ParseConfig(dbURL)
|
||||
require.NoError(t, err, "Failed to parse database URL")
|
||||
dbConfig.MaxConns = 1
|
||||
dbPool, err := pgxpool.NewWithConfig(ctx, dbConfig)
|
||||
require.NoError(t, err, "Failed to connect to test database")
|
||||
|
||||
db := database.New(dbPool)
|
||||
|
||||
Reference in New Issue
Block a user