Skip to content

Commit

Permalink
Merge pull request #130260 from nvanbenschoten/backport24.1-130084
Browse files Browse the repository at this point in the history
release-24.1: raft: fix flaky leader index in waitLeader function
  • Loading branch information
nvanbenschoten authored Sep 6, 2024
2 parents b76b7cb + 86c8928 commit 74b7327
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion pkg/raft/rafttest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ go_test(
deps = [
"//pkg/raft",
"//pkg/raft/raftpb",
"//pkg/testutils/skip",
],
)
15 changes: 5 additions & 10 deletions pkg/raft/rafttest/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/raft"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
)

func TestBasicProgress(t *testing.T) {
Expand Down Expand Up @@ -53,9 +52,6 @@ func TestBasicProgress(t *testing.T) {
}

func TestRestart(t *testing.T) {
// TODO(pav-kv): de-flake it. See https://github.com/etcd-io/raft/issues/181.
skip.UnderStress(t, "the test is flaky")

peers := []raft.Peer{{ID: 1, Context: nil}, {ID: 2, Context: nil}, {ID: 3, Context: nil}, {ID: 4, Context: nil}, {ID: 5, Context: nil}}
nt := newRaftNetwork(1, 2, 3, 4, 5)

Expand Down Expand Up @@ -135,23 +131,22 @@ func TestPause(t *testing.T) {
}

func waitLeader(ns []*node) int {
var l map[uint64]struct{}
var lindex int

l := make(map[uint64]struct{})
for {
l = make(map[uint64]struct{})
clear(l)
lindex := -1

for i, n := range ns {
lead := n.Status().SoftState.Lead
if lead != 0 {
if lead != raft.None {
l[lead] = struct{}{}
if n.id == lead {
lindex = i
}
}
}

if len(l) == 1 {
if len(l) == 1 && lindex != -1 {
return lindex
}
}
Expand Down

0 comments on commit 74b7327

Please sign in to comment.