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:
co-authored by
Alessio Treglia
Alexander Bezobchuk
parent
f640ad6cea
commit
5e16c215ba
+18
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user