Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: async prune test is failed #924

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading