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

De-flake TestNRGUnsuccessfulVoteRequestDoesntResetElectionTimer #5891

Merged
merged 1 commit into from
Sep 16, 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
17 changes: 17 additions & 0 deletions server/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ func TestNRGStepDownOnSameTermDoesntClearVote(t *testing.T) {
}

func TestNRGUnsuccessfulVoteRequestDoesntResetElectionTimer(t *testing.T) {
// This test relies on nodes not hitting their election timer too often,
// otherwise the step later where we capture the election time before and
// after the failed vote request will flake.
origMinElectionTimeout, origMaxElectionTimeout := minElectionTimeout, maxElectionTimeout
minElectionTimeout, maxElectionTimeout = time.Second*5, time.Second*10
defer func() {
minElectionTimeout, maxElectionTimeout = origMinElectionTimeout, origMaxElectionTimeout
}()

c := createJetStreamClusterExplicit(t, "R3S", 3)
defer c.shutdown()
c.waitOnLeader()
Expand All @@ -449,6 +458,14 @@ func TestNRGUnsuccessfulVoteRequestDoesntResetElectionTimer(t *testing.T) {
defer nc.Close()

rg := c.createRaftGroup("TEST", 3, newStateAdder)

// Because the election timer is quite high, we want to kick a node into
// campaigning before it naturally needs to, otherwise the test takes a
// long time just to pick a leader.
for _, n := range rg {
n.node().Campaign()
break
}
rg.waitOnLeader()
leader := rg.leader().node().(*raft)
follower := rg.nonLeader().node().(*raft)
Expand Down