[#1381] engine: Fix tests

Drop not required `Eventually` calls.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-09-17 11:24:48 +03:00
parent f71418b73c
commit 0b87be804a
4 changed files with 11 additions and 47 deletions

View file

@ -3,7 +3,6 @@ package shard
import ( import (
"context" "context"
"testing" "testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "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-node/pkg/local_object_storage/internal/testutil"
@ -58,19 +57,14 @@ func testShard(t *testing.T, hasWriteCache bool, payloadSize int) {
_, err := sh.Put(context.Background(), putPrm) _, err := sh.Put(context.Background(), putPrm)
require.NoError(t, err) require.NoError(t, err)
_, err = testGet(t, sh, getPrm, hasWriteCache) _, err = sh.Get(context.Background(), getPrm)
require.NoError(t, err) require.NoError(t, err)
if hasWriteCache { if hasWriteCache {
sh.FlushWriteCache(context.Background(), FlushWriteCachePrm{ignoreErrors: false}) require.NoError(t, sh.FlushWriteCache(context.Background(), FlushWriteCachePrm{ignoreErrors: false}))
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.Delete(context.Background(), delPrm)
require.NoError(t, err)
_, err = sh.Get(context.Background(), getPrm) _, err = sh.Get(context.Background(), getPrm)
require.True(t, client.IsErrObjectNotFound(err)) require.True(t, client.IsErrObjectNotFound(err))

View file

@ -5,11 +5,9 @@ import (
"context" "context"
"errors" "errors"
"testing" "testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "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-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" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
@ -49,7 +47,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
getPrm.SetAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := sh.Get(context.Background(), getPrm)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, obj, res.Object()) require.Equal(t, obj, res.Object())
}) })
@ -67,7 +65,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
getPrm.SetAddress(object.AddressOf(obj)) getPrm.SetAddress(object.AddressOf(obj))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := sh.Get(context.Background(), getPrm)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, obj, res.Object()) require.Equal(t, obj, res.Object())
}) })
@ -95,13 +93,13 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
getPrm.SetAddress(object.AddressOf(child)) getPrm.SetAddress(object.AddressOf(child))
res, err := testGet(t, sh, getPrm, hasWriteCache) res, err := sh.Get(context.Background(), getPrm)
require.NoError(t, err) require.NoError(t, err)
require.True(t, binaryEqual(child, res.Object())) require.True(t, binaryEqual(child, res.Object()))
getPrm.SetAddress(object.AddressOf(parent)) getPrm.SetAddress(object.AddressOf(parent))
_, err = testGet(t, sh, getPrm, hasWriteCache) _, err = sh.Get(context.Background(), getPrm)
var si *objectSDK.SplitInfoError var si *objectSDK.SplitInfoError
require.True(t, errors.As(err, &si)) require.True(t, errors.As(err, &si))
@ -115,19 +113,6 @@ func testShardGet(t *testing.T, hasWriteCache bool) {
}) })
} }
func testGet(t *testing.T, sh *Shard, getPrm GetPrm, hasWriteCache bool) (GetRes, error) {
res, err := sh.Get(context.Background(), getPrm)
if hasWriteCache {
require.Eventually(t, func() bool {
if client.IsErrObjectNotFound(err) {
res, err = sh.Get(context.Background(), getPrm)
}
return !client.IsErrObjectNotFound(err)
}, time.Second, time.Millisecond*100)
}
return res, err
}
// binary equal is used when object contains empty lists in the structure and // binary equal is used when object contains empty lists in the structure and
// requre.Equal fails on comparing <nil> and []{} lists. // requre.Equal fails on comparing <nil> and []{} lists.
func binaryEqual(a, b *objectSDK.Object) bool { func binaryEqual(a, b *objectSDK.Object) bool {

View file

@ -4,11 +4,9 @@ import (
"context" "context"
"errors" "errors"
"testing" "testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "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-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" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -46,7 +44,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
headPrm.SetAddress(object.AddressOf(obj)) headPrm.SetAddress(object.AddressOf(obj))
res, err := testHead(t, sh, headPrm, hasWriteCache) res, err := sh.Head(context.Background(), headPrm)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, obj.CutPayload(), res.Object()) require.Equal(t, obj.CutPayload(), res.Object())
}) })
@ -74,7 +72,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
var siErr *objectSDK.SplitInfoError var siErr *objectSDK.SplitInfoError
_, err = testHead(t, sh, headPrm, hasWriteCache) _, err = sh.Head(context.Background(), headPrm)
require.True(t, errors.As(err, &siErr)) require.True(t, errors.As(err, &siErr))
headPrm.SetAddress(object.AddressOf(parent)) headPrm.SetAddress(object.AddressOf(parent))
@ -85,16 +83,3 @@ func testShardHead(t *testing.T, hasWriteCache bool) {
require.Equal(t, parent.CutPayload(), head.Object()) require.Equal(t, parent.CutPayload(), head.Object())
}) })
} }
func testHead(t *testing.T, sh *Shard, headPrm HeadPrm, hasWriteCache bool) (HeadRes, error) {
res, err := sh.Head(context.Background(), headPrm)
if hasWriteCache {
require.Eventually(t, func() bool {
if client.IsErrObjectNotFound(err) {
res, err = sh.Head(context.Background(), headPrm)
}
return !client.IsErrObjectNotFound(err)
}, time.Second, time.Millisecond*100)
}
return res, err
}

View file

@ -48,7 +48,7 @@ func testShardInhume(t *testing.T, hasWriteCache bool) {
_, err := sh.Put(context.Background(), putPrm) _, err := sh.Put(context.Background(), putPrm)
require.NoError(t, err) require.NoError(t, err)
_, err = testGet(t, sh, getPrm, hasWriteCache) _, err = sh.Get(context.Background(), getPrm)
require.NoError(t, err) require.NoError(t, err)
_, err = sh.Inhume(context.Background(), inhPrm) _, err = sh.Inhume(context.Background(), inhPrm)