Ensure txns are closed so we can wipe the db for other tests

This commit is contained in:
Kegan Dougal 2024-05-17 16:09:02 +01:00
parent 5028f93f83
commit af1f34861e
2 changed files with 6 additions and 1 deletions

View File

@ -151,6 +151,7 @@ func TestClearStuckInvites(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer tx.Rollback()
// users in room B (bob) and F (doris) should be reset. // users in room B (bob) and F (doris) should be reset.
tokens, err := tokensTable.TokenForEachDevice(tx) tokens, err := tokensTable.TokenForEachDevice(tx)

View File

@ -1,11 +1,13 @@
package testutils package testutils
import ( import (
"context"
"database/sql" "database/sql"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"time"
) )
var Quiet = false var Quiet = false
@ -64,7 +66,9 @@ func PrepareDBConnectionString() (connStr string) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
_, err = db.Exec(`DROP SCHEMA public CASCADE; ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_, err = db.ExecContext(ctx, `DROP SCHEMA public CASCADE;
CREATE SCHEMA public;`) CREATE SCHEMA public;`)
if err != nil { if err != nil {
panic(err) panic(err)