From 387d8b0339b3cbe068aec69171727a112c0cb156 Mon Sep 17 00:00:00 2001 From: Xinyuan Du Date: Thu, 21 Mar 2024 23:11:12 +0800 Subject: [PATCH] Fix flaky leader index in waitLeader function Signed-off-by: Xinyuan Du --- rafttest/node_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rafttest/node_test.go b/rafttest/node_test.go index 6fd4f582..87d726c2 100644 --- a/rafttest/node_test.go +++ b/rafttest/node_test.go @@ -129,7 +129,7 @@ func TestPause(t *testing.T) { func waitLeader(ns []*node) int { var l map[uint64]struct{} - var lindex int + var lindex = -1 for { l = make(map[uint64]struct{}) @@ -144,7 +144,7 @@ func waitLeader(ns []*node) int { } } - if len(l) == 1 { + if len(l) == 1 && lindex != -1 { return lindex } }