Skip to content

Commit

Permalink
De-flake RAFT state adder tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
  • Loading branch information
MauriceVanVeen authored and wallyqs committed Dec 13, 2024
1 parent 3d2a3b3 commit b606d5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions server/raft_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func (a *stateAdder) stop() {
a.Lock()
defer a.Unlock()
a.n.Stop()
a.n.WaitForStop()
}

// Restart the group
Expand Down Expand Up @@ -273,6 +274,11 @@ func (a *stateAdder) restart() {
panic(err)
}

// Must reset in-memory state.
// A real restart would not preserve it, but more importantly we have no way to detect if we
// already applied an entry. So, the sum must only be updated based on append entries or snapshots.
a.sum = 0

a.n, err = a.s.startRaftNode(globalAccountName, a.cfg, pprofLabels{})
if err != nil {
panic(err)
Expand Down
5 changes: 3 additions & 2 deletions server/raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ func TestNRGHeartbeatOnLeaderChange(t *testing.T) {
leader := rg.leader().(*stateAdder)
leader.proposeDelta(22)
leader.proposeDelta(-11)
leader.proposeDelta(-11)
rg.waitOnTotal(t, 0)
leader.proposeDelta(-10)
// Must observe forward progress, so each iteration will check +1 total.
rg.waitOnTotal(t, int64(i+1))
leader.stop()
leader.restart()
rg.waitOnLeader()
Expand Down

0 comments on commit b606d5b

Please sign in to comment.