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 TestNRGCandidateDontStepdownDueToLeaderOfPreviousTerm #5992

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
27 changes: 21 additions & 6 deletions server/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,22 +876,37 @@ func TestNRGCandidateDontStepdownDueToLeaderOfPreviousTerm(t *testing.T) {
candidateTerm uint64 = 100
)

// Create a candidate that has received entries while they were a follower in a previous term
rg.lockAll()
leader := rg.leader().node().(*raft)
candidate := rg.nonLeader().node().(*raft)
candidate.Lock()

// We don't want any of the non-leaders to process vote responses, otherwise the node we turned
// into a candidate might win the election and take over leader role, so blackhole the IPQ.
for _, n := range rg {
if n.node() == leader {
continue
}
rn := n.node().(*raft)
rn.votes.unregister()
rn.votes = newIPQueue[*voteResponse](rn.s, "vote request blackhole",
ipqSizeCalculation(func(e *voteResponse) uint64 {
return 2 // Bigger than the size limit below, so always fails to push anything.
}),
ipqLimitBySize[*voteResponse](1),
)
}

// Create a candidate that has received entries while they were a follower in a previous term
candidate.switchState(Candidate)
candidate.pterm = candidatePterm
candidate.pindex = candidatePindex
candidate.term = candidateTerm
candidate.Unlock()

// Leader term is behind candidate
leader := rg.leader().node().(*raft)
leader.Lock()
leader.term = candidatePterm
leader.pterm = candidatePterm
leader.pindex = candidatePindex
leader.Unlock()
rg.unlockAll()

// Subscribe to the append entry subject.
sub, err := nc.SubscribeSync(leader.asubj)
Expand Down