[#633] shard/test: Fix TestCounters()

Introduced in 362f24953a, forgotten to be changed because test
generator didn't provide payload size.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-10-31 14:16:34 +03:00 committed by Evgenii Stratonikov
parent b8f79f4227
commit 00aa6d9749
2 changed files with 19 additions and 7 deletions

View file

@ -49,6 +49,7 @@ func GenerateObjectWithCIDWithPayload(cnr cid.ID, data []byte) *objectSDK.Object
obj.SetContainerID(cnr) obj.SetContainerID(cnr)
obj.SetVersion(&ver) obj.SetVersion(&ver)
obj.SetPayload(data) obj.SetPayload(data)
obj.SetPayloadSize(uint64(len(data)))
obj.SetPayloadChecksum(csum) obj.SetPayloadChecksum(csum)
obj.SetPayloadHomomorphicHash(csumTZ) obj.SetPayloadHomomorphicHash(csumTZ)

View file

@ -5,6 +5,7 @@ import (
"path/filepath" "path/filepath"
"sync" "sync"
"testing" "testing"
"time"
objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" objectcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
@ -151,11 +152,11 @@ func TestCounters(t *testing.T) {
var totalPayload int64 var totalPayload int64
expectedSizes := make(map[string]int64) expectedLogicalSizes := make(map[string]int64)
for i := range oo { for i := range oo {
cnr, _ := oo[i].ContainerID() cnr, _ := oo[i].ContainerID()
oSize := int64(oo[i].PayloadSize()) oSize := int64(oo[i].PayloadSize())
expectedSizes[cnr.EncodeToString()] += oSize expectedLogicalSizes[cnr.EncodeToString()] += oSize
totalPayload += 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(physical))
require.Equal(t, uint64(objNumber), mm.getObjectCounter(logical)) 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()) require.Equal(t, totalPayload, mm.payloadSize())
t.Run("inhume_GC", func(t *testing.T) { t.Run("inhume_GC", func(t *testing.T) {
@ -182,11 +183,15 @@ func TestCounters(t *testing.T) {
_, err := sh.Inhume(context.Background(), prm) _, err := sh.Inhume(context.Background(), prm)
require.NoError(t, err) 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), mm.getObjectCounter(physical))
require.Equal(t, uint64(objNumber-inhumedNumber), mm.getObjectCounter(logical)) 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()) require.Equal(t, totalPayload, mm.payloadSize())
oo = oo[inhumedNumber:] oo = oo[inhumedNumber:]
@ -205,9 +210,15 @@ func TestCounters(t *testing.T) {
_, err := sh.Inhume(context.Background(), prm) _, err := sh.Inhume(context.Background(), prm)
require.NoError(t, err) 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, phy, mm.getObjectCounter(physical))
require.Equal(t, logic-uint64(inhumedNumber), mm.getObjectCounter(logical)) 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()) require.Equal(t, totalPayload, mm.payloadSize())
oo = oo[inhumedNumber:] oo = oo[inhumedNumber:]
@ -233,9 +244,9 @@ func TestCounters(t *testing.T) {
totalRemovedpayload += removedPayload totalRemovedpayload += removedPayload
cnr, _ := oo[i].ContainerID() 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()) require.Equal(t, totalPayload-int64(totalRemovedpayload), mm.payloadSize())
}) })
} }