From 40b556fc197666a454b4b84a518c6c59e78ce4bb Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 24 Aug 2023 22:17:27 +0300 Subject: [PATCH] [#647] objsvc/search: Improve testing coverage Signed-off-by: Evgenii Stratonikov --- pkg/services/object/search/search_test.go | 113 +++++++++++++++++----- 1 file changed, 90 insertions(+), 23 deletions(-) diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 9bfc54739..09d98eff2 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -22,6 +22,7 @@ import ( frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" + oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test" sessionsdk "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" "github.com/google/uuid" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -60,6 +61,14 @@ func (e testEpochReceiver) Epoch() (uint64, error) { return uint64(e), nil } +type errIDWriter struct { + err error +} + +func (e errIDWriter) WriteIDs(ids []oid.ID) error { + return e.err +} + func (s *simpleIDWriter) WriteIDs(ids []oid.ID) error { s.ids = append(s.ids, ids...) return nil @@ -194,6 +203,20 @@ func TestGetLocalOnly(t *testing.T) { w := new(simpleIDWriter) p := newPrm(cnr, w) + err := svc.Search(ctx, p) + require.ErrorIs(t, err, testErr) + }) + t.Run("FAIL while writing ID", func(t *testing.T) { + storage := newTestStorage() + svc := newSvc(storage) + + cnr := cidtest.ID() + storage.addResult(cnr, []oid.ID{oidtest.ID()}, nil) + + testErr := errors.New("any error") + w := errIDWriter{testErr} + p := newPrm(cnr, w) + err := svc.Search(ctx, p) require.ErrorIs(t, err, testErr) }) @@ -280,33 +303,34 @@ func TestGetRemoteSmall(t *testing.T) { return p } + var addr oid.Address + addr.SetContainer(id) + + ns, as := testNodeMatrix(t, placementDim) + + builder := &testPlacementBuilder{ + vectors: map[string][][]netmap.NodeInfo{ + addr.EncodeToString(): ns, + }, + } + + c1 := newTestStorage() + ids1 := generateIDs(10) + + c2 := newTestStorage() + ids2 := generateIDs(10) + + svc := newSvc(builder, &testClientCache{ + clients: map[string]*testStorage{ + as[0][0]: c1, + as[0][1]: c2, + }, + }) + t.Run("OK", func(t *testing.T) { - var addr oid.Address - addr.SetContainer(id) - - ns, as := testNodeMatrix(t, placementDim) - - builder := &testPlacementBuilder{ - vectors: map[string][][]netmap.NodeInfo{ - addr.EncodeToString(): ns, - }, - } - - c1 := newTestStorage() - ids1 := generateIDs(10) c1.addResult(id, ids1, nil) - - c2 := newTestStorage() - ids2 := generateIDs(10) c2.addResult(id, ids2, nil) - svc := newSvc(builder, &testClientCache{ - clients: map[string]*testStorage{ - as[0][0]: c1, - as[0][1]: c2, - }, - }) - w := new(simpleIDWriter) p := newPrm(id, w) @@ -319,6 +343,49 @@ func TestGetRemoteSmall(t *testing.T) { require.Contains(t, w.ids, id) } }) + t.Run("non-local fail is not a FAIL", func(t *testing.T) { + testErr := errors.New("opaque") + + c1.addResult(id, ids1, nil) + c2.addResult(id, nil, testErr) + + w := new(simpleIDWriter) + p := newPrm(id, w) + + err := svc.Search(ctx, p) + require.NoError(t, err) + require.Equal(t, ids1, w.ids) + }) + t.Run("client init fail is not a FAIL", func(t *testing.T) { + svc := newSvc(builder, &testClientCache{ + clients: map[string]*testStorage{ + as[0][0]: c1, + }, + }) + c1.addResult(id, ids1, nil) + c2.addResult(id, ids2, nil) + + w := new(simpleIDWriter) + p := newPrm(id, w) + + err := svc.Search(ctx, p) + require.NoError(t, err) + require.Equal(t, ids1, w.ids) + }) + t.Run("context is respected", func(t *testing.T) { + c1.addResult(id, ids1, nil) + c2.addResult(id, ids2, nil) + + w := new(simpleIDWriter) + p := newPrm(id, w) + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + err := svc.Search(ctx, p) + require.NoError(t, err) + require.Empty(t, w.ids) + }) } func TestGetFromPastEpoch(t *testing.T) {