Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/store/datastore/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down