From 1a1f497e2c88fc52b6740eb97ac8b3c61bbad3f0 Mon Sep 17 00:00:00 2001 From: Dave New Date: Fri, 24 Nov 2023 04:19:13 +0200 Subject: [PATCH] fix: closing db connection in tests --- testhelpers/testhelpers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testhelpers/testhelpers.go b/testhelpers/testhelpers.go index 8b68bd80a..0db2a3cff 100644 --- a/testhelpers/testhelpers.go +++ b/testhelpers/testhelpers.go @@ -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 { @@ -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