From 00aa6d974990b5a84a2fcdff1f9e91d2f6b30011 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 31 Oct 2023 14:16:34 +0300 Subject: [PATCH] [#633] shard/test: Fix TestCounters() Introduced in 362f24953a7, forgotten to be changed because test generator didn't provide payload size. Signed-off-by: Evgenii Stratonikov --- .../internal/testutil/object.go | 1 + .../shard/metrics_test.go | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/pkg/local_object_storage/internal/testutil/object.go b/pkg/local_object_storage/internal/testutil/object.go index 573a099ff..60e9211d5 100644 --- a/pkg/local_object_storage/internal/testutil/object.go +++ b/pkg/local_object_storage/internal/testutil/object.go @@ -49,6 +49,7 @@ func GenerateObjectWithCIDWithPayload(cnr cid.ID, data []byte) *objectSDK.Object obj.SetContainerID(cnr) obj.SetVersion(&ver) obj.SetPayload(data) + obj.SetPayloadSize(uint64(len(data))) obj.SetPayloadChecksum(csum) obj.SetPayloadHomomorphicHash(csumTZ) diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index 107938139..7724aa222 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "sync" "testing" + "time" objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor" @@ -151,11 +152,11 @@ func TestCounters(t *testing.T) { var totalPayload int64 - expectedSizes := make(map[string]int64) + expectedLogicalSizes := make(map[string]int64) for i := range oo { cnr, _ := oo[i].ContainerID() oSize := int64(oo[i].PayloadSize()) - expectedSizes[cnr.EncodeToString()] += oSize + expectedLogicalSizes[cnr.EncodeToString()] += oSize totalPayload += oSize } @@ -170,7 +171,7 @@ func TestCounters(t *testing.T) { require.Equal(t, uint64(objNumber), mm.getObjectCounter(physical)) require.Equal(t, uint64(objNumber), mm.getObjectCounter(logical)) - require.Equal(t, expectedSizes, mm.containerSizes()) + require.Equal(t, expectedLogicalSizes, mm.containerSizes()) require.Equal(t, totalPayload, mm.payloadSize()) t.Run("inhume_GC", func(t *testing.T) { @@ -182,11 +183,15 @@ func TestCounters(t *testing.T) { _, err := sh.Inhume(context.Background(), prm) require.NoError(t, err) + + cid, ok := oo[i].ContainerID() + require.True(t, ok) + expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize()) } require.Equal(t, uint64(objNumber), mm.getObjectCounter(physical)) require.Equal(t, uint64(objNumber-inhumedNumber), mm.getObjectCounter(logical)) - require.Equal(t, expectedSizes, mm.containerSizes()) + require.Equal(t, expectedLogicalSizes, mm.containerSizes()) require.Equal(t, totalPayload, mm.payloadSize()) oo = oo[inhumedNumber:] @@ -205,9 +210,15 @@ func TestCounters(t *testing.T) { _, err := sh.Inhume(context.Background(), prm) require.NoError(t, err) + for i := 0; i < inhumedNumber; i++ { + cid, ok := oo[i].ContainerID() + require.True(t, ok) + expectedLogicalSizes[cid.EncodeToString()] -= int64(oo[i].PayloadSize()) + } + require.Equal(t, phy, mm.getObjectCounter(physical)) require.Equal(t, logic-uint64(inhumedNumber), mm.getObjectCounter(logical)) - require.Equal(t, expectedSizes, mm.containerSizes()) + require.Equal(t, expectedLogicalSizes, mm.containerSizes()) require.Equal(t, totalPayload, mm.payloadSize()) oo = oo[inhumedNumber:] @@ -233,9 +244,9 @@ func TestCounters(t *testing.T) { totalRemovedpayload += removedPayload cnr, _ := oo[i].ContainerID() - expectedSizes[cnr.EncodeToString()] -= int64(removedPayload) + expectedLogicalSizes[cnr.EncodeToString()] -= int64(removedPayload) } - require.Equal(t, expectedSizes, mm.containerSizes()) + require.Equal(t, expectedLogicalSizes, mm.containerSizes()) require.Equal(t, totalPayload-int64(totalRemovedpayload), mm.payloadSize()) }) }