Skip to content

Commit

Permalink
Problem: async prune test is failed (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Nov 13, 2024
1 parent e790d23 commit 2d4f901
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,18 @@ func TestMultiStore_Pruning(t *testing.T) {
ms.Commit()
}

for _, v := range tc.saved {
_, err := ms.CacheMultiStoreWithVersion(v)
require.NoError(t, err, "expected no error when loading height: %d", v)
for _, v := range tc.deleted {
// Ensure async pruning is done
checkErr := func() bool {
_, err := ms.CacheMultiStoreWithVersion(v)
return err != nil
}
require.Eventually(t, checkErr, 1*time.Second, 10*time.Millisecond, "expected error when loading height: %d", v)
}

for _, v := range tc.deleted {
for _, v := range tc.saved {
_, err := ms.CacheMultiStoreWithVersion(v)
require.Error(t, err, "expected error when loading height: %d", v)
require.NoError(t, err, "expected no error when loading height: %d", v)
}
})
}
Expand All @@ -564,16 +568,6 @@ func TestMultiStore_Pruning_SameHeightsTwice(t *testing.T) {

require.Equal(t, numVersions, lastCommitInfo.Version)

for v := int64(1); v < numVersions-int64(keepRecent); v++ {
err := ms.LoadVersion(v)
require.Error(t, err, "expected error when loading pruned height: %d", v)
}

for v := (numVersions - int64(keepRecent)); v < numVersions; v++ {
err := ms.LoadVersion(v)
require.NoError(t, err, "expected no error when loading height: %d", v)
}

// Get latest
err := ms.LoadVersion(numVersions - 1)
require.NoError(t, err)
Expand All @@ -588,6 +582,17 @@ func TestMultiStore_Pruning_SameHeightsTwice(t *testing.T) {
// Ensure that can commit one more height with no panic
lastCommitInfo = ms.Commit()
require.Equal(t, numVersions+1, lastCommitInfo.Version)
isPruned := func() bool {
ls := ms.Commit() // to flush the batch with the pruned heights
for v := int64(1); v < numVersions-int64(keepRecent); v++ {
if err := ms.LoadVersion(v); err == nil {
require.NoError(t, ms.LoadVersion(ls.Version)) // load latest
return false
}
}
return true
}
require.Eventually(t, isPruned, 1000*time.Second, 10*time.Millisecond, "expected error when loading pruned heights")
}

func TestMultiStore_PruningRestart(t *testing.T) {
Expand Down Expand Up @@ -618,10 +623,18 @@ func TestMultiStore_PruningRestart(t *testing.T) {
actualHeightToPrune = ms.pruningManager.GetPruningHeight(ms.LatestVersion())
require.Equal(t, int64(8), actualHeightToPrune)

for v := int64(1); v <= actualHeightToPrune; v++ {
_, err := ms.CacheMultiStoreWithVersion(v)
require.Error(t, err, "expected error when loading height: %d", v)
// Ensure async pruning is done
isPruned := func() bool {
ms.Commit() // to flush the batch with the pruned heights
for v := int64(1); v <= actualHeightToPrune; v++ {
if _, err := ms.CacheMultiStoreWithVersion(v); err == nil {
return false
}
}
return true
}

require.Eventually(t, isPruned, 1*time.Second, 10*time.Millisecond, "expected error when loading pruned heights")
}

// TestUnevenStoresHeightCheck tests if loading root store correctly errors when
Expand Down

0 comments on commit 2d4f901

Please sign in to comment.