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

@ -151,7 +151,7 @@ test:
$(TEST_OPTS) ./test.sh 2>&1 | tee test-$(TEST_SUFFIX).log $(TEST_OPTS) ./test.sh 2>&1 | tee test-$(TEST_SUFFIX).log
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test-$(TEST_SUFFIX).log ! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test-$(TEST_SUFFIX).log
test-small: test-smoke:
$(info log-file: test-$(TEST_SUFFIX).log) $(info log-file: test-$(TEST_SUFFIX).log)
PASSES="fmt build unit" ./test.sh 2<&1 | tee test-$(TEST_SUFFIX).log PASSES="fmt build unit" ./test.sh 2<&1 | tee test-$(TEST_SUFFIX).log

View File

@ -364,9 +364,13 @@ func (rc *raftNode) maybeTriggerSnapshot(applyDoneC <-chan struct{}) {
return return
} }
// wait until all committed entries are applied // wait until all committed entries are applied (or server is closed)
if applyDoneC != nil { 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) 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) { func (clus *cluster) closeNoErrors(t *testing.T) {
t.Log("closing cluster...")
if err := clus.Close(); err != nil { if err := clus.Close(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
t.Log("closing cluster [done]")
} }
// TestProposeOnCommit starts three nodes and feeds commits back into the proposal // TestProposeOnCommit starts three nodes and feeds commits back into the proposal