Skip to content

Commit b606d5b

Browse files
MauriceVanVeenwallyqs
authored andcommitted
De-flake RAFT state adder tests
Signed-off-by: Maurice van Veen <[email protected]>
1 parent 3d2a3b3 commit b606d5b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

server/raft_helpers_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func (a *stateAdder) stop() {
246246
a.Lock()
247247
defer a.Unlock()
248248
a.n.Stop()
249+
a.n.WaitForStop()
249250
}
250251

251252
// Restart the group
@@ -273,6 +274,11 @@ func (a *stateAdder) restart() {
273274
panic(err)
274275
}
275276

277+
// Must reset in-memory state.
278+
// A real restart would not preserve it, but more importantly we have no way to detect if we
279+
// already applied an entry. So, the sum must only be updated based on append entries or snapshots.
280+
a.sum = 0
281+
276282
a.n, err = a.s.startRaftNode(globalAccountName, a.cfg, pprofLabels{})
277283
if err != nil {
278284
panic(err)

server/raft_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,9 @@ func TestNRGHeartbeatOnLeaderChange(t *testing.T) {
605605
leader := rg.leader().(*stateAdder)
606606
leader.proposeDelta(22)
607607
leader.proposeDelta(-11)
608-
leader.proposeDelta(-11)
609-
rg.waitOnTotal(t, 0)
608+
leader.proposeDelta(-10)
609+
// Must observe forward progress, so each iteration will check +1 total.
610+
rg.waitOnTotal(t, int64(i+1))
610611
leader.stop()
611612
leader.restart()
612613
rg.waitOnLeader()

0 commit comments

Comments
 (0)