Use t.TempDir for SQLite databases, so tests don't rip out each others databases (#2950)

This should hopefully finally fix issues about `disk I/O error` as seen
[here](https://gitlab.alpinelinux.org/alpine/aports/-/jobs/955030/raw)

Hopefully this will also fix `SSL accept attempt failed` issues by
disabling HTTP keep alives when generating a config for CI.
This commit is contained in:
Till 2023-01-23 13:17:15 +01:00 committed by GitHub
parent 430932f0f1
commit 48fa869fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 31 deletions

View file

@ -22,6 +22,7 @@ import (
"os"
"os/exec"
"os/user"
"path/filepath"
"testing"
"github.com/lib/pq"
@ -103,13 +104,10 @@ func currentUser() string {
// TODO: namespace for concurrent package tests
func PrepareDBConnectionString(t *testing.T, dbType DBType) (connStr string, close func()) {
if dbType == DBTypeSQLite {
// this will be made in the current working directory which namespaces concurrent package runs correctly
dbname := "dendrite_test.db"
// this will be made in the t.TempDir, which is unique per test
dbname := filepath.Join(t.TempDir(), "dendrite_test.db")
return fmt.Sprintf("file:%s", dbname), func() {
err := os.Remove(dbname)
if err != nil {
t.Fatalf("failed to cleanup sqlite db '%s': %s", dbname, err)
}
t.Cleanup(func() {}) // removes the t.TempDir
}
}
@ -176,7 +174,7 @@ func WithAllDatabases(t *testing.T, testFn func(t *testing.T, db DBType)) {
for dbName, dbType := range dbs {
dbt := dbType
t.Run(dbName, func(tt *testing.T) {
//tt.Parallel()
tt.Parallel()
testFn(tt, dbt)
})
}