Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: make TestLeaderPriority stable #8592

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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