diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 089277ccac..760e624eb9 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -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 diff --git a/snapshots/util_test.go b/snapshots/util_test.go index 72b236dafc..78c870b90a 100644 --- a/snapshots/util_test.go +++ b/snapshots/util_test.go @@ -83,7 +83,6 @@ func TestChunkWriter(t *testing.T) { } func TestChunkReader(t *testing.T) { - ch := makeChunks([][]byte{ {1, 2, 3}, {4}, @@ -150,9 +149,9 @@ func TestChunkReader(t *testing.T) { close(pch) go func() { - chunkReader = snapshots.NewChunkReader(pch) - buf = []byte{0, 0, 0, 0} - _, err = chunkReader.Read(buf) + chunkReader := snapshots.NewChunkReader(pch) + buf := []byte{0, 0, 0, 0} + _, err := chunkReader.Read(buf) require.NoError(t, err) assert.Equal(t, []byte{1, 2, 3, 0}, buf)