[#651] shard/test: Refactor Shard_Delete
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
306f12e6c5
commit
33dc88b374
1 changed files with 37 additions and 61 deletions
|
@ -12,88 +12,64 @@ 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.Parallel()
|
t.Run("small object without write cache", func(t *testing.T) {
|
||||||
|
|
||||||
t.Run("without write cache", func(t *testing.T) {
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testShardDelete(t, false)
|
testShard(t, false, 1<<5)
|
||||||
})
|
})
|
||||||
|
|
||||||
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
|
||||||
|
putPrm.SetObject(obj)
|
||||||
|
|
||||||
var getPrm GetPrm
|
var getPrm GetPrm
|
||||||
|
getPrm.SetAddress(object.AddressOf(obj))
|
||||||
|
|
||||||
t.Run("big object", func(t *testing.T) {
|
var delPrm DeletePrm
|
||||||
testutil.AddPayload(obj, 1<<20)
|
delPrm.SetAddresses(object.AddressOf(obj))
|
||||||
|
|
||||||
putPrm.SetObject(obj)
|
_, err := sh.Put(context.Background(), putPrm)
|
||||||
getPrm.SetAddress(object.AddressOf(obj))
|
require.NoError(t, err)
|
||||||
|
|
||||||
var delPrm DeletePrm
|
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
||||||
delPrm.SetAddresses(object.AddressOf(obj))
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err := sh.Put(context.Background(), putPrm)
|
if hasWriteCache {
|
||||||
require.NoError(t, err)
|
require.Eventually(t, func() bool {
|
||||||
|
|
||||||
_, 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, 100*time.Millisecond)
|
|
||||||
} else {
|
|
||||||
_, err = sh.Delete(context.Background(), delPrm)
|
_, err = sh.Delete(context.Background(), delPrm)
|
||||||
require.NoError(t, err)
|
return err == nil
|
||||||
}
|
}, 30*time.Second, 10*time.Millisecond)
|
||||||
|
} else {
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Delete(context.Background(), delPrm)
|
||||||
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)
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = sh.Get(context.Background(), getPrm)
|
_, err = sh.Get(context.Background(), getPrm)
|
||||||
require.NoError(t, err)
|
require.True(t, client.IsErrObjectNotFound(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))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue