test: fix data race in snapshots.ChunkReader test (#7299)

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Erik Grinaker
2020-09-14 14:00:08 +01:00
committed by GitHub
co-authored by Alessio Treglia Alexander Bezobchuk
parent f640ad6cea
commit 5e16c215ba
2 changed files with 21 additions and 8 deletions
+18 -4
View File
@@ -123,6 +123,8 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
}))
}
snapshotInterval := uint64(2)
snapshotTimeout := 1 * time.Minute
snapshotDir, err := ioutil.TempDir("", "baseapp")
require.NoError(t, err)
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snapshotDir)
@@ -133,7 +135,7 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
app := setupBaseApp(t, append(options,
SetSnapshotStore(snapshotStore),
SetSnapshotInterval(2),
SetSnapshotInterval(snapshotInterval),
SetPruning(sdk.PruningOptions{KeepEvery: 1}),
routerOpt)...)
@@ -161,9 +163,21 @@ func setupBaseAppWithSnapshots(t *testing.T, blocks uint, blockTxs int, options
app.EndBlock(abci.RequestEndBlock{Height: height})
app.Commit()
// Wait for snapshot to be taken, since it happens asynchronously. This
// heuristic is likely to be flaky on low-IO machines.
time.Sleep(time.Duration(int(height)*blockTxs) * 200 * time.Millisecond)
// Wait for snapshot to be taken, since it happens asynchronously.
if uint64(height)%snapshotInterval == 0 {
start := time.Now()
for {
if time.Since(start) > snapshotTimeout {
t.Errorf("timed out waiting for snapshot after %v", snapshotTimeout)
}
snapshot, err := snapshotStore.Get(uint64(height), snapshottypes.CurrentFormat)
require.NoError(t, err)
if snapshot != nil {
break
}
time.Sleep(100 * time.Millisecond)
}
}
}
return app, teardown