Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean committed Dec 11, 2024
1 parent aa66f65 commit 0bdd1c3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions storage/pruning/fullHistoryPruningStorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"fmt"
"github.com/multiversx/mx-chain-go/testscommon"
"math"
"path/filepath"
"sync"
Expand Down Expand Up @@ -399,3 +400,33 @@ func TestFullHistoryPruningStorer_IsInterfaceNil(t *testing.T) {
fhps, _ = pruning.NewFullHistoryPruningStorer(fhArgs)
require.False(t, fhps.IsInterfaceNil())
}

func TestFullHistoryPruningStorer_changeEpochClosesOldDbs(t *testing.T) {
t.Parallel()

shouldCleanCalled := false
args := getDefaultArgs()
fhArgs := pruning.FullHistoryStorerArgs{
StorerArgs: args,
NumOfOldActivePersisters: 2,
}
fhArgs.OldDataCleanerProvider = &testscommon.OldDataCleanerProviderStub{
ShouldCleanCalled: func() bool {
shouldCleanCalled = true
return true
},
}
fhps, err := pruning.NewFullHistoryPruningStorer(fhArgs)
require.Nil(t, err)

numEpochsChanged := 10
startEpoch := uint32(0)
for i := 0; i < numEpochsChanged; i++ {
startEpoch++
key := []byte(fmt.Sprintf("key-%d", i))
_, _ = fhps.GetFromEpoch(key, startEpoch)
err = fhps.ChangeEpochSimple(startEpoch)
require.Nil(t, err)
}
require.True(t, shouldCleanCalled)
}

0 comments on commit 0bdd1c3

Please sign in to comment.