From c429d4e955b7bcd16a0c6d94297e9df5b0f19f16 Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 4 Sep 2024 11:15:32 -0400 Subject: [PATCH] raft: fix flaky leader index in waitLeader function Fixes #127413. This commit bypasses the larger rebase in #122133 to pick up the test flake fix in https://github.com/etcd-io/raft/pull/188. There was some discussion in https://github.com/etcd-io/raft/issues/181 about alternatives for fixing this test. For now, we stick with a direct cherry-pick. Release note: None --- pkg/raft/rafttest/node_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/raft/rafttest/node_test.go b/pkg/raft/rafttest/node_test.go index 4323b76005b9..8b886b7c2971 100644 --- a/pkg/raft/rafttest/node_test.go +++ b/pkg/raft/rafttest/node_test.go @@ -137,7 +137,7 @@ func TestPause(t *testing.T) { func waitLeader(ns []*node) int { var l map[pb.PeerID]struct{} - var lindex int + var lindex = -1 for { l = make(map[pb.PeerID]struct{}) @@ -152,7 +152,7 @@ func waitLeader(ns []*node) int { } } - if len(l) == 1 { + if len(l) == 1 && lindex != -1 { return lindex } }