Skip to content

Commit

Permalink
pool: Leave failed postgres db state in pool tests.
Browse files Browse the repository at this point in the history
This modifies the pool tests to avoid cleaning up the postgres data when
there is a test failure and the -failfast test flag is set so the
contents of the database can be examined.

Since a failed run with -failfast will no longer purge the data, it also
adds logic to purge the data prior to running the tests to ensure any
previous failed runs are cleaned up on subsequent runs.
  • Loading branch information
davecgh committed Sep 21, 2023
1 parent a8cab74 commit ebb6bd5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package pool

import (
"flag"
"os"
"testing"

Expand Down Expand Up @@ -128,6 +129,17 @@ func TestPool(t *testing.T) {
boltDB.Close()
}

// Cleanup postgres DB from potential failed previous runs.
postgresDB, err := setupPostgresDB()
if err != nil {
t.Fatalf("setupPostgresDB error: %v", err)
}
err = postgresDB.purge()
if err != nil {
t.Fatalf("postgres teardown error: %v", err)
}
postgresDB.Close()

// Run all tests with postgres DB.
for testName, test := range tests {
postgresDB, err := setupPostgresDB()
Expand All @@ -139,9 +151,11 @@ func TestPool(t *testing.T) {

t.Run(testName+"_Postgres", test)

err = postgresDB.purge()
if err != nil {
t.Fatalf("postgres teardown error: %v", err)
if !t.Failed() || flag.Lookup("test.failfast") == nil {
err = postgresDB.purge()
if err != nil {
t.Fatalf("postgres teardown error: %v", err)
}
}

postgresDB.Close()
Expand Down

0 comments on commit ebb6bd5

Please sign in to comment.