shard/test: Fix TestCounters() #771

Merged
fyrchik merged 2 commits from fyrchik/frostfs-node:add-metrics into master 2023-10-31 12:53:31 +00:00
2 changed files with 20 additions and 7 deletions

View file

@ -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)

View file

@ -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())
})
}
@ -268,6 +279,7 @@ func shardWithMetrics(t *testing.T, path string) (*Shard, *metricsStore) {
meta.WithPath(filepath.Join(path, "meta")),
meta.WithEpochState(epochState{})),
WithMetricsWriter(mm),
WithGCRemoverSleepInterval(time.Hour),
)
require.NoError(t, sh.Open(context.Background()))
require.NoError(t, sh.Init(context.Background()))