Skip to content

Commit

Permalink
Close connection to base DB after cleanup
Browse files Browse the repository at this point in the history
When running multiple quick tests in parallel it's possible to get a connection failure due to too many clients connected.
  • Loading branch information
ebabani committed Jan 8, 2024
1 parent 8080014 commit 7923c6f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ services:
- "-c"
- "log_statement=all"
- "-c"
- "max_connections=1000"
- "max_connections=100"
ports:
- "5433:5432"

2 changes: 2 additions & 0 deletions testdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func create(t testing.TB, conf Config, migrator Migrator) (*Config, *sql.DB) {
}

t.Cleanup(func() {
defer baseDB.Close()

// Close the testDB
if err := db.Close(); err != nil {
t.Fatalf("could not close test database: '%s': %s", instance.Database, err)
Expand Down
4 changes: 2 additions & 2 deletions testdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func TestExtensionsInstalled(t *testing.T) {
}

// These two tests should show that creating many different testdbs in parallel
// is quite fast. Each of the tests creates and destroys 10 databases.
// is quite fast. Each of the tests creates and destroys 50 databases.
func TestParallel1(t *testing.T) {
t.Parallel()
ctx := context.Background()

for i := 0; i < 10; i++ {
for i := 0; i < 50; i++ {
t.Run(fmt.Sprintf("subtest_%d", i), func(t *testing.T) {
t.Parallel()
db := New(t)
Expand Down

0 comments on commit 7923c6f

Please sign in to comment.