Add db controlled mutex to prevent database init occuring during another test as this breaks the tests on MariaDB

This commit is contained in:
Keith Martin
2024-10-01 19:35:54 +10:00
parent d256744058
commit f3b924378f
21 changed files with 536 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/photoprism/get"
"github.com/photoprism/photoprism/internal/testextras"
)
func TestMain(m *testing.M) {
@@ -18,6 +19,14 @@ func TestMain(m *testing.M) {
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
caller := "internal/commands/commands_test.go/TestMain"
dbc, err := testextras.AcquireDBMutex(log, caller)
if err != nil {
log.Error("FAIL")
os.Exit(1)
}
defer testextras.UnlockDBMutex(dbc.Db())
c := config.NewTestConfig("commands")
get.SetConfig(c)
@@ -29,6 +38,8 @@ func TestMain(m *testing.M) {
// Run unit tests.
code := m.Run()
testextras.ReleaseDBMutex(dbc.Db(), log, caller, code)
// Close database connection.
c.CloseDb()