mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Clarify the use of gooseMutex to proect goose internal state
Signed-off-by: Brian Meek <brian@hntlabs.com>
This commit is contained in:
parent
55b3edcaae
commit
2b45bd6781
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue