From 193fe6cac7eea06282b1803aee327abf283979ef Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Wed, 4 Sep 2024 16:23:56 +0800 Subject: [PATCH] *: make `TestLeaderPriority` stable (#8592) close tikv/pd#8447 Signed-off-by: Ryan Leung --- tests/server/member/member_test.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/server/member/member_test.go b/tests/server/member/member_test.go index 6cd9eacddf1..2d0c9098153 100644 --- a/tests/server/member/member_test.go +++ b/tests/server/member/member_test.go @@ -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 }) }