Skip to content

Commit

Permalink
*: fix the race of TestRaftClusterMultipleRestart (#8686)
Browse files Browse the repository at this point in the history
close #8543

Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] authored Oct 11, 2024
1 parent 48e72f1 commit 982fa22
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/replication/replication_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ func (m *ModeManager) Run(ctx context.Context) {
select {
case <-timer.C:
case <-ctx.Done():
log.Info("replication mode manager is stopped")
return
}

Expand Down Expand Up @@ -383,6 +384,7 @@ func (m *ModeManager) Run(ctx context.Context) {
}()

wg.Wait()
log.Info("replication mode manager is stopped")
}

func minimalUpVoters(rule *placement.Rule, upStores, downStores []*core.StoreInfo) int {
Expand Down
5 changes: 5 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ func (c *RaftCluster) Stop() {
log.Info("raft cluster is stopped")
}

// Wait blocks until the cluster is stopped. Only for test purpose.
func (c *RaftCluster) Wait() {
c.wg.Wait()
}

// IsRunning return if the cluster is running.
func (c *RaftCluster) IsRunning() bool {
c.RLock()
Expand Down
2 changes: 2 additions & 0 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ func TestRaftClusterMultipleRestart(t *testing.T) {
// let the job run at small interval
re.NoError(failpoint.Enable("github.com/tikv/pd/server/cluster/highFrequencyClusterJobs", `return(true)`))
for i := 0; i < 100; i++ {
// See https://github.com/tikv/pd/issues/8543
rc.Wait()
err = rc.Start(leaderServer.GetServer())
re.NoError(err)
time.Sleep(time.Millisecond)
Expand Down

0 comments on commit 982fa22

Please sign in to comment.