Skip to content

Commit

Permalink
test: speed up domain.Close() in test (#46610)
Browse files Browse the repository at this point in the history
ref #45961
  • Loading branch information
Defined2014 authored Sep 4, 2023
1 parent 1cf3201 commit 01731da
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions owner/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ func (*mockManager) SetOwnerOpValue(_ context.Context, op OpType) error {
return nil
}

func sleepContext(ctx context.Context, delay time.Duration) {
select {
case <-ctx.Done():
case <-time.After(delay):
}
}

// CampaignOwner implements Manager.CampaignOwner interface.
func (m *mockManager) CampaignOwner() error {
m.wg.Add(1)
Expand All @@ -142,10 +149,10 @@ func (m *mockManager) CampaignOwner() error {
return
case <-m.resignDone:
m.RetireOwner()
time.Sleep(1 * time.Second) // Give a chance to the other owner managers to get owner.
sleepContext(m.ctx, 1*time.Second) // Give a chance to the other owner managers to get owner.
default:
m.toBeOwner()
time.Sleep(1 * time.Second)
sleepContext(m.ctx, 1*time.Second) // Speed up domain.Close()
logutil.BgLogger().Debug("owner manager tick", zap.String("category", "ddl"), zap.String("ID", m.id),
zap.String("ownerKey", m.key), zap.String("currentOwner", util.MockGlobalStateEntry.OwnerKey(m.storeID, m.key).GetOwner()))
}
Expand Down

0 comments on commit 01731da

Please sign in to comment.