[#1445] metabase/test: Add test for graves of the 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
181a8f0013
commit
262a9ccd0c
1 changed files with 65 additions and 0 deletions
|
@ -14,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) {
|
||||
|
@ -465,3 +466,67 @@ 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 range numGraves / 2 {
|
||||
expEpochs = append(expEpochs, rand.Uint64())
|
||||
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, 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