Compare commits

...

3 commits

Author SHA1 Message Date
d6c7424eaa [#651] engine/test: Speedup StorageEngine_Inhume
All checks were successful
DCO action / DCO (pull_request) Successful in 4m29s
Build / Build Components (1.20) (pull_request) Successful in 8m45s
Build / Build Components (1.21) (pull_request) Successful in 8m39s
Vulncheck / Vulncheck (pull_request) Successful in 8m44s
Tests and linters / Staticcheck (pull_request) Successful in 12m37s
Tests and linters / Tests (1.20) (pull_request) Successful in 12m59s
Tests and linters / Tests (1.21) (pull_request) Successful in 13m3s
Tests and linters / Lint (pull_request) Successful in 13m26s
Tests and linters / Tests with -race (pull_request) Successful in 13m58s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-11-29 10:53:24 +03:00
dcd2966177 [#651] shard/test: Speedup Shard_Delete
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-11-29 10:53:24 +03:00
33dc88b374 [#651] shard/test: Refactor Shard_Delete
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-11-29 10:53:24 +03:00
2 changed files with 40 additions and 61 deletions

View file

@ -36,6 +36,7 @@ func TestStorageEngine_Inhume(t *testing.T) {
link.SetSplitID(splitID) link.SetSplitID(splitID)
t.Run("delete small object", func(t *testing.T) { t.Run("delete small object", func(t *testing.T) {
t.Parallel()
e := testNewEngine(t).setShardsNum(t, 1).engine e := testNewEngine(t).setShardsNum(t, 1).engine
defer e.Close(context.Background()) defer e.Close(context.Background())
@ -54,6 +55,7 @@ func TestStorageEngine_Inhume(t *testing.T) {
}) })
t.Run("delete big object", func(t *testing.T) { t.Run("delete big object", func(t *testing.T) {
t.Parallel()
s1 := testNewShard(t, 1) s1 := testNewShard(t, 1)
s2 := testNewShard(t, 2) s2 := testNewShard(t, 2)

View file

@ -12,35 +12,43 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestShard_Delete(t *testing.T) { func TestShard_Delete_SmallObject(t *testing.T) {
t.Run("small object without write cache", func(t *testing.T) {
t.Parallel() t.Parallel()
testShard(t, false, 1<<5)
t.Run("without write cache", func(t *testing.T) {
t.Parallel()
testShardDelete(t, false)
}) })
t.Run("with write cache", func(t *testing.T) { t.Run("small object with write cache", func(t *testing.T) {
t.Parallel() t.Parallel()
testShardDelete(t, true) testShard(t, true, 1<<5)
}) })
} }
func testShardDelete(t *testing.T, hasWriteCache bool) { 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) sh := newShard(t, hasWriteCache)
cnr := cidtest.ID() cnr := cidtest.ID()
obj := testutil.GenerateObjectWithCID(cnr) obj := testutil.GenerateObjectWithCID(cnr)
testutil.AddAttribute(obj, "foo", "bar") testutil.AddAttribute(obj, "foo", "bar")
testutil.AddPayload(obj, payloadSize)
var putPrm PutPrm var putPrm PutPrm
var getPrm GetPrm
t.Run("big object", func(t *testing.T) {
testutil.AddPayload(obj, 1<<20)
putPrm.SetObject(obj) putPrm.SetObject(obj)
var getPrm GetPrm
getPrm.SetAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
var delPrm DeletePrm var delPrm DeletePrm
@ -53,10 +61,11 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
require.NoError(t, err) require.NoError(t, err)
if hasWriteCache { if hasWriteCache {
sh.FlushWriteCache(context.Background(), FlushWriteCachePrm{ignoreErrors: false})
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
_, err = sh.Delete(context.Background(), delPrm) _, err = sh.Delete(context.Background(), delPrm)
return err == nil return err == nil
}, 30*time.Second, 100*time.Millisecond) }, 30*time.Second, 10*time.Millisecond)
} else { } else {
_, err = sh.Delete(context.Background(), delPrm) _, err = sh.Delete(context.Background(), delPrm)
require.NoError(t, err) require.NoError(t, err)
@ -64,36 +73,4 @@ func testShardDelete(t *testing.T, hasWriteCache bool) {
_, err = sh.Get(context.Background(), getPrm) _, err = sh.Get(context.Background(), getPrm)
require.True(t, client.IsErrObjectNotFound(err)) require.True(t, client.IsErrObjectNotFound(err))
})
t.Run("small object", func(t *testing.T) {
obj := testutil.GenerateObjectWithCID(cnr)
testutil.AddAttribute(obj, "foo", "bar")
testutil.AddPayload(obj, 1<<5)
putPrm.SetObject(obj)
getPrm.SetAddress(object.AddressOf(obj))
var delPrm DeletePrm
delPrm.SetAddresses(object.AddressOf(obj))
_, err := sh.Put(context.Background(), putPrm)
require.NoError(t, err)
_, err = sh.Get(context.Background(), getPrm)
require.NoError(t, err)
if hasWriteCache {
require.Eventually(t, func() bool {
_, err = sh.Delete(context.Background(), delPrm)
return err == nil
}, 10*time.Second, 100*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))
})
} }