From be8b99e3bc1e733f1f22ef9890988a9eb89cb6bd Mon Sep 17 00:00:00 2001 From: Aleksey Savchuk Date: Thu, 12 Dec 2024 15:42:23 +0300 Subject: [PATCH] [#1445] metabase/test: Add test for tombstones of the new format Test iterating over graveyard populated with tombstones of both old and new formats. Signed-off-by: Aleksey Savchuk --- .../metabase/graveyard_test.go | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/pkg/local_object_storage/metabase/graveyard_test.go b/pkg/local_object_storage/metabase/graveyard_test.go index 1d03741dc..de1f98e62 100644 --- a/pkg/local_object_storage/metabase/graveyard_test.go +++ b/pkg/local_object_storage/metabase/graveyard_test.go @@ -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 ( + numTombstones = 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 numTombstones / 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) +}