raftExample: Allow closing raftexample node when snapshotting.

Fix race that made the raftExample test fail.
This commit is contained in:
Piotr Tabor
2021-02-25 22:34:23 +01:00
parent 9563698f64
commit 3976d68ed3
3 changed files with 9 additions and 3 deletions

View File

@@ -364,9 +364,13 @@ func (rc *raftNode) maybeTriggerSnapshot(applyDoneC <-chan struct{}) {
return
}
// wait until all committed entries are applied
// wait until all committed entries are applied (or server is closed)
if applyDoneC != nil {
<-applyDoneC
select {
case <-applyDoneC:
case <-rc.stopc:
return
}
}
log.Printf("start snapshot [applied index: %d | last snapshot index: %d]", rc.appliedIndex, rc.snapshotIndex)

View File

@@ -94,9 +94,11 @@ func (clus *cluster) Close() (err error) {
}
func (clus *cluster) closeNoErrors(t *testing.T) {
t.Log("closing cluster...")
if err := clus.Close(); err != nil {
t.Fatal(err)
}
t.Log("closing cluster [done]")
}
// TestProposeOnCommit starts three nodes and feeds commits back into the proposal