diff --git a/server/store/datastore/engine_test.go b/server/store/datastore/engine_test.go index 74ed9032c39..7d5d4e998d3 100644 --- a/server/store/datastore/engine_test.go +++ b/server/store/datastore/engine_test.go @@ -38,10 +38,16 @@ func testDriverConfig() (driver, config string) { // newTestStore creates a new database connection for testing purposes. // The database driver and connection string are provided by // environment variables, with fallback to in-memory sqlite. -func newTestStore(t *testing.T, tables ...any) (*storage, func()) { +func newTestStore(t *testing.T, tables ...any) (store *storage, closer func()) { engine, err := xorm.NewEngine(testDriverConfig()) require.NoError(t, err) + // MaxOpenConns=1 and MaxIdleConns=1 are required for in-memory sqlite: + // without them the pool drops idle connections, destroying the in-memory + // schema between calls and breaking migrations. + engine.SetMaxOpenConns(1) + engine.SetMaxIdleConns(1) + for _, table := range tables { if err := engine.Sync(table); err != nil { t.Error(err)