[#647] objsvc/search: Improve testing coverage

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-08-24 22:17:27 +03:00
parent 4db2cbc927
commit 40b556fc19

View file

@ -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) {