Skip to content

Commit

Permalink
fix: closing db connection in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davenewza committed Nov 24, 2023
1 parent 4b31821 commit 1a1f497
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func SetupDatabaseForTestCase(ctx context.Context, dbConnInfo *db.ConnectionInfo
if err != nil {
return nil, err
}
defer mainDB.Close()

_, err = mainDB.Exec("select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname = '" + dbName + "' and pg_stat_activity.pid <> pg_backend_pid();")
if err != nil {
Expand All @@ -86,7 +87,7 @@ func SetupDatabaseForTestCase(ctx context.Context, dbConnInfo *db.ConnectionInfo
// at the end of the test. We need to explicitly close the connection
// so the mainDB connection can drop the database.
testDBConnInfo := dbConnInfo.WithDatabase(dbName)

fmt.Println(testDBConnInfo.String())
database, err := db.New(ctx, testDBConnInfo.String())
if err != nil {
return nil, err
Expand Down

0 comments on commit 1a1f497

Please sign in to comment.