[#1445] metabase/test: Add test for graves of new format
Test iterating over graveyard populated with graves of both old and new formats, i. e. without and with an expiration epoch, respectively. Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
efec26b8ef
commit
3cbd8be700
1 changed files with 67 additions and 0 deletions
|
@ -2,6 +2,7 @@ package meta_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
||||
|
@ -13,6 +14,7 @@ import (
|
|||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func TestDB_IterateDeletedObjects_EmptyDB(t *testing.T) {
|
||||
|
@ -472,3 +474,68 @@ func TestDB_InhumeTombstones(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Zero(t, counter)
|
||||
}
|
||||
|
||||
func TestIterateOverGraveyardWithDifferentGraveFormats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type grave struct {
|
||||
addr, tomb oid.Address
|
||||
expEpoch uint64
|
||||
}
|
||||
|
||||
var (
|
||||
numGraves = 20
|
||||
|
||||
expectedGraves []grave
|
||||
actualGraves []grave
|
||||
eg errgroup.Group
|
||||
)
|
||||
|
||||
db := newDB(t)
|
||||
defer func() { require.NoError(t, db.Close(context.Background())) }()
|
||||
|
||||
var expEpochs []uint64
|
||||
for i := range numGraves / 2 {
|
||||
expEpochs = append(expEpochs, uint64(i))
|
||||
expEpochs = append(expEpochs, meta.NoExpirationEpoch)
|
||||
}
|
||||
rand.Shuffle(len(expEpochs), func(i, j int) {
|
||||
expEpochs[i], expEpochs[j] = expEpochs[j], expEpochs[i]
|
||||
})
|
||||
|
||||
for _, expEpoch := range expEpochs {
|
||||
cnt := cidtest.ID()
|
||||
|
||||
addr := oidtest.Address()
|
||||
addr.SetContainer(cnt)
|
||||
|
||||
tomb := oidtest.Address()
|
||||
tomb.SetContainer(cnt)
|
||||
|
||||
expectedGraves = append(expectedGraves, grave{
|
||||
addr: addr, tomb: tomb, expEpoch: expEpoch,
|
||||
})
|
||||
|
||||
eg.Go(func() error {
|
||||
var prm meta.InhumePrm
|
||||
prm.SetAddresses(addr)
|
||||
prm.SetTombstoneAddress(tomb)
|
||||
prm.SetTombstoneExpEpoch(expEpoch)
|
||||
|
||||
_, err := db.Inhume(context.Background(), prm)
|
||||
return err
|
||||
})
|
||||
}
|
||||
require.NoError(t, eg.Wait())
|
||||
|
||||
var iterPrm meta.GraveyardIterationPrm
|
||||
iterPrm.SetHandler(func(o meta.TombstonedObject) error {
|
||||
actualGraves = append(actualGraves, grave{
|
||||
o.Address(), o.Tombstone(), o.ExpirationEpoch(),
|
||||
})
|
||||
return nil
|
||||
})
|
||||
require.NoError(t, db.IterateOverGraveyard(context.Background(), iterPrm))
|
||||
|
||||
require.ElementsMatch(t, expectedGraves, actualGraves)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue