frostfs-node/pkg/local_object_storage/shard/delete_test.go
Alexander Chuprov 2302e5d342 [#651] shard/test: Refactor Shard_Delete
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-11-30 13:19:43 +00:00

75 lines
1.8 KiB
Go

package shard
import (
"context"
"testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
"github.com/stretchr/testify/require"
)
func TestShard_Delete_SmallObject(t *testing.T) {
t.Run("small object without write cache", func(t *testing.T) {
t.Parallel()
testShard(t, false, 1<<5)
})
t.Run("small object with write cache", func(t *testing.T) {
t.Parallel()
testShard(t, true, 1<<5)
})
}
func TestShard_Delete_BigObject(t *testing.T) {
t.Run("big object without write cache", func(t *testing.T) {
t.Parallel()
testShard(t, false, 1<<20)
})
t.Run("big object with write cache", func(t *testing.T) {
t.Parallel()
testShard(t, true, 1<<20)
})
}
func testShard(t *testing.T, hasWriteCache bool, payloadSize int) {
sh := newShard(t, hasWriteCache)
cnr := cidtest.ID()
obj := testutil.GenerateObjectWithCID(cnr)
testutil.AddAttribute(obj, "foo", "bar")
testutil.AddPayload(obj, payloadSize)
var putPrm PutPrm
putPrm.SetObject(obj)
var getPrm GetPrm
getPrm.SetAddress(object.AddressOf(obj))
var delPrm DeletePrm
delPrm.SetAddresses(object.AddressOf(obj))
_, err := sh.Put(context.Background(), putPrm)
require.NoError(t, err)
_, err = testGet(t, sh, getPrm, hasWriteCache)
require.NoError(t, err)
if hasWriteCache {
require.Eventually(t, func() bool {
_, err = sh.Delete(context.Background(), delPrm)
return err == nil
}, 30*time.Second, 10*time.Millisecond)
} else {
_, err = sh.Delete(context.Background(), delPrm)
require.NoError(t, err)
}
_, err = sh.Get(context.Background(), getPrm)
require.True(t, client.IsErrObjectNotFound(err))
}