Skip to content

Commit

Permalink
*: make TestLeaderPriority stable (#8592)
Browse files Browse the repository at this point in the history
close #8447

Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx authored Sep 4, 2024
1 parent 750d475 commit 193fe6c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions tests/server/member/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,33 @@ func TestLeaderPriority(t *testing.T) {

re.NotEmpty(cluster.WaitLeader())

leader1, err := cluster.GetServer("pd1").GetEtcdLeader()
leader, err := cluster.GetServer("pd1").GetEtcdLeader()
re.NoError(err)
server1 := cluster.GetServer(leader1)
addr := server1.GetConfig().ClientUrls
server := cluster.GetServer(leader)
addr := server.GetConfig().ClientUrls
// PD leader should sync with etcd leader.
testutil.Eventually(re, func() bool {
return cluster.GetLeader() == leader1
leader, err := cluster.GetServer("pd1").GetEtcdLeader()
if err != nil {
return false
}
return cluster.GetLeader() == leader
})
// Bind a lower priority to current leader.
post(t, re, addr+"/pd/api/v1/members/name/"+leader1, `{"leader-priority": -1}`)
post(t, re, addr+"/pd/api/v1/members/name/"+leader, `{"leader-priority": -1}`)

// Wait etcd leader change.
leader2 := waitEtcdLeaderChange(re, server1, leader1)
waitEtcdLeaderChange(re, server, leader)
// PD leader should sync with etcd leader again.
testutil.Eventually(re, func() bool {
return cluster.GetLeader() == leader2
etcdLeader, err := server.GetEtcdLeader()
if err != nil {
return false
}
if cluster.GetLeader() == etcdLeader {
return true
}
return false
})
}

Expand Down

0 comments on commit 193fe6c

Please sign in to comment.