mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test: add test database cleaner in subprocess (#19844)
fixes https://github.com/coder/internal/issues/927 Adds a small subprocess that outlives the testing process to clean up any leaked test databases.
This commit is contained in:
@@ -3,6 +3,7 @@ package dbtestutil_test
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -110,3 +111,27 @@ func TestOpen_ValidDBFrom(t *testing.T) {
|
||||
require.True(t, rows.Next())
|
||||
require.NoError(t, rows.Close())
|
||||
}
|
||||
|
||||
func TestOpen_Panic(t *testing.T) {
|
||||
t.Skip("unskip this to manually test that we don't leak a database into postgres")
|
||||
t.Parallel()
|
||||
if !dbtestutil.WillUsePostgres() {
|
||||
t.Skip("this test requires postgres")
|
||||
}
|
||||
|
||||
_, err := dbtestutil.Open(t)
|
||||
require.NoError(t, err)
|
||||
panic("now check SELECT datname FROM pg_database;")
|
||||
}
|
||||
|
||||
func TestOpen_Timeout(t *testing.T) {
|
||||
t.Skip("unskip this and set a short timeout to manually test that we don't leak a database into postgres")
|
||||
t.Parallel()
|
||||
if !dbtestutil.WillUsePostgres() {
|
||||
t.Skip("this test requires postgres")
|
||||
}
|
||||
|
||||
_, err := dbtestutil.Open(t)
|
||||
require.NoError(t, err)
|
||||
time.Sleep(11 * time.Minute)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user