diff --git a/internal/sqlutil/migrate.go b/internal/sqlutil/migrate.go index cb0aed7d3..56d906f29 100644 --- a/internal/sqlutil/migrate.go +++ b/internal/sqlutil/migrate.go @@ -48,9 +48,11 @@ type Migration struct { Down func(ctx context.Context, txn *sql.Tx) error } +// Gaurs the internal state of Goose from being modified by concurrent tests or goroutines +var gooseMutex sync.Mutex + // Migrator type Migrator struct { - gooseMutex sync.Mutex db *sql.DB migrations []Migration knownMigrations map[string]struct{} @@ -82,8 +84,8 @@ func (m *Migrator) AddMigrations(migrations ...Migration) { // Up executes all migrations in order they were added. func (m *Migrator) Up(ctx context.Context) error { - m.gooseMutex.Lock() - defer m.gooseMutex.Unlock() + gooseMutex.Lock() + defer gooseMutex.Unlock() var ( err error dendriteVersion = internal.VersionString() diff --git a/syncapi/sync/requestpool_test.go b/syncapi/sync/requestpool_test.go index 5142f5dd3..3e5769d8c 100644 --- a/syncapi/sync/requestpool_test.go +++ b/syncapi/sync/requestpool_test.go @@ -128,19 +128,15 @@ func TestRequestPool_updatePresence(t *testing.T) { go rp.cleanPresence(db, time.Millisecond*50) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - beforeCount := func() int { - publisher.lock.Lock() - defer publisher.lock.Unlock() - return publisher.count - }() + publisher.lock.Lock() + beforeCount := publisher.count + publisher.lock.Unlock() rp.updatePresence(db, tt.args.presence, tt.args.userID) - func() { - publisher.lock.Lock() - defer publisher.lock.Unlock() - if tt.wantIncrease && publisher.count <= beforeCount { - t.Fatalf("expected count to increase: %d <= %d", publisher.count, beforeCount) - } - }() + publisher.lock.Lock() + if tt.wantIncrease && publisher.count <= beforeCount { + t.Fatalf("expected count to increase: %d <= %d", publisher.count, beforeCount) + } + publisher.lock.Unlock() time.Sleep(tt.args.sleep) }) }