From 33ce2f09aa2a795b4b61da163d254e0a685f2293 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Wed, 8 Jun 2022 01:59:31 +0000 Subject: [PATCH 1/6] add drafts of upsert test cases Signed-off-by: Kosuke Morimoto --- .../core/ngt/handler/grpc/upsert_test.go | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index 669111404f..599dbf5043 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -168,6 +168,95 @@ func Test_server_StreamUpsert(t *testing.T) { } return nil } + + /* + Upsert test cases (only test float32 unless otherwise specified): + - Equivalence Class Testing ( 1000 vectors inserted before an upsert ) + - case 1.1: success upsert with new ID + - case 1.2: success upsert with existent ID + - case 2.1: fail upsert with one different dimension vector (type: uint8) + - case 2.2: fail upsert with one different dimension vector (type: float32) + - Boundary Value Testing ( 1000 vectors inserted before an upsert if not specified ) + - case 1.1: fail upsert with "" as ID + - case 1.2: fail upsert to empty index with "" as ID + - case 2.1: success upsert with ^@ as duplicated ID + - case 2.2: success upsert with ^@ as new ID + - case 2.3: success upsert to empty index with ^@ as new ID + - case 2.4: success upsert with ^I as duplicated ID + - case 2.5: success upsert with ^I as new ID + - case 2.6: success upsert to empty index with ^I as new ID + - case 2.7: success upsert with ^J as duplicated ID + - case 2.8: success upsert with ^J as new ID + - case 2.9: success upsert to empty index with ^J as new ID + - case 2.10: success upsert with ^M as duplicated ID + - case 2.11: success upsert with ^M as new ID + - case 2.12: success upsert to empty index with ^M as new ID + - case 2.13: success upsert with ^[ as duplicated ID + - case 2.14: success upsert with ^[ as new ID + - case 2.15: success upsert to empty index with ^[ as new ID + - case 2.16: success upsert with ^? as duplicated ID + - case 2.17: success upsert with ^? as new ID + - case 2.18: success upsert to empty index with ^? as new ID + - case 3.1: success upsert with utf-8 ID from utf-8 index + - case 3.2: success upsert with utf-8 ID from s-jis index + - case 3.3: success upsert with utf-8 ID from euc-jp index + - case 3.4: success upsert with s-jis ID from utf-8 index + - case 3.5: success upsert with s-jis ID from s-jis index + - case 3.6: success upsert with s-jis ID from euc-jp index + - case 3.4: success upsert with euc-jp ID from utf-8 index + - case 3.5: success upsert with euc-jp ID from s-jis index + - case 3.6: success upsert with euc-jp ID from euc-jp index + - case 4.1: success upsert with ๐Ÿ˜€ as duplicated ID + - case 4.2: success upsert with ๐Ÿ˜€ as new ID + - case 4.3: success upsert to empty index with ๐Ÿ˜€ as new ID + - case 5.1: success upsert with one 0 value vector with duplicated ID (type: uint8) + - case 5.2: success upsert with one 0 value vector with new ID (type: uint8) + - case 5.3: success upsert to empty index with one 0 value vector with new ID (type: uint8) + - case 5.4: success upsert with one +0 value vector with duplicated ID (type: float32) + - case 5.5: success upsert with one +0 value vector with new ID (type: float32) + - case 5.6: success upsert to empty index with one +0 value vector with new ID (type: float32) + - case 5.7: success upsert with one -0 value vector with duplicated ID (type: float32) + - case 5.8: success upsert with one -0 value vector with new ID (type: float32) + - case 5.9: success upsert to empty index with one -0 value vector with new ID (type: float32) + - case 6.1: success upsert with one min value vector with duplicated ID (type: uint8) + - case 6.2: success upsert with one min value vector with new ID (type: uint8) + - case 6.3: success upsert to empty index with one min value vector with new ID (type: uint8) + - case 6.4: success upsert with one min value vector with duplicated ID (type: float32) + - case 6.5: success upsert with one min value vector with new ID (type: float32) + - case 6.6: success upsert to empty index with one min value vector with new ID (type: float32) + - case 7.1: success upsert with one max value vector with duplicated ID (type: uint8) + - case 7.2: success upsert with one max value vector with new ID (type: uint8) + - case 7.3: success upsert to empty index with one max value vector with new ID (type: uint8) + - case 7.4: success upsert with one max value vector with duplicated ID (type: float32) + - case 7.5: success upsert with one max value vector (type: float32) + - case 7.6: success upsert to empty index with one max value vector (type: float32) + - case 8.1: success upsert with one NaN value vector with duplicated ID (type: float32) // NOTE: To fix it, it is necessary to check all of vector value + - case 8.2: success upsert with one NaN value vector with new ID (type: float32) // NOTE: To fix it, it is necessary to check all of vector value + - case 8.3: success upsert to empty index with one NaN value vector with new ID (type: float32) // NOTE: To fix it, it is necessary to check all of vector value + - case 9.1: success upsert with one +inf value vector with duplicated ID (type: float32) + - case 9.2: success upsert with one +inf value vector with new ID (type: float32) + - case 9.3: success upsert to empty index with one +inf value vector with new ID (type: float32) + - case 9.4: success upsert with one -inf value vector with duplicated ID (type: float32) + - case 9.5: success upsert with one -inf value vector with new ID (type: float32) + - case 9.6: success upsert to empty index with one -inf value vector with new ID (type: float32) + - case 10.1: fail upsert with one nil vector + - case 10.2: fail upsert to empty index with one nil vector + - case 11.1: fail upsert with one empty vector + - case 11.2: fail upsert to empty index with one empty vector + - Decision Table Testing + - case 1.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is true + - case 1.2: success upsert with one different vector, duplicated ID and SkipStrictExistsCheck is true + - case 1.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is true + - case 2.1: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is true + - case 2.2: success upsert with one different vector, new ID and SkipStrictExistsCheck is true + - case 2.3: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is true + - case 3.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false + - case 3.2: success upsert with one different vector, duplicated ID and SkipStrictExistsCheck is false + - case 3.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is false + - case 4.1: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is false + - case 4.2: success upsert with one different vector, new ID and SkipStrictExistsCheck is false + - case 4.3: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is false + */ tests := []test{ // TODO test cases /* From 2a213d3789e4a2bf90850ffae69e8d87937fe287 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Thu, 9 Jun 2022 03:39:25 +0000 Subject: [PATCH 2/6] implement tests Signed-off-by: Kosuke Morimoto --- .../core/ngt/handler/grpc/upsert_test.go | 1615 +++++++++++++++-- 1 file changed, 1487 insertions(+), 128 deletions(-) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index 599dbf5043..afedb84408 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -17,156 +17,118 @@ package grpc import ( "context" + "math" "reflect" "testing" "github.com/vdaas/vald/apis/grpc/v1/payload" "github.com/vdaas/vald/apis/grpc/v1/vald" + "github.com/vdaas/vald/internal/config" + "github.com/vdaas/vald/internal/conv" + "github.com/vdaas/vald/internal/core/algorithm/ngt" "github.com/vdaas/vald/internal/errgroup" "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc/codes" + "github.com/vdaas/vald/internal/net/grpc/status" + "github.com/vdaas/vald/internal/test/data/request" + "github.com/vdaas/vald/internal/test/data/vector" "github.com/vdaas/vald/internal/test/goleak" "github.com/vdaas/vald/pkg/agent/core/ngt/service" ) func Test_server_Upsert(t *testing.T) { t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + type args struct { - ctx context.Context - req *payload.Upsert_Request - } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + ctx context.Context + indexID string + indexVector []float32 + req *payload.Upsert_Request } type want struct { - wantLoc *payload.Object_Location - err error + code codes.Code + wantUUID string } type test struct { name string args args - fields fields want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(args) + beforeFunc func(args) (Server, error) afterFunc func(args) } - defaultCheckFunc := func(w want, gotLoc *payload.Object_Location, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) - } - if !reflect.DeepEqual(gotLoc, w.wantLoc) { - return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotLoc, w.wantLoc) - } - return nil - } - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - ctx: nil, - req: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - ctx: nil, - req: nil, - }, - fields: fields { - name: "", - ip: "", - ngt: nil, - eg: nil, - streamConcurrency: 0, - }, - want: want{}, - checkFunc: defaultCheckFunc, - } - }(), - */ - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) - if test.beforeFunc != nil { - test.beforeFunc(test.args) + defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { + if err != nil { + st, ok := status.FromError(err) + if !ok { + errors.Errorf("got error cannot convert to Status: \"%#v\"", err) } - if test.afterFunc != nil { - defer test.afterFunc(test.args) - } - checkFunc := test.checkFunc - if test.checkFunc == nil { - checkFunc = defaultCheckFunc - } - s := &server{ - name: test.fields.name, - ip: test.fields.ip, - ngt: test.fields.ngt, - eg: test.fields.eg, - streamConcurrency: test.fields.streamConcurrency, + if st.Code() != w.code { + return errors.Errorf("got code: \"%#v\",\n\t\t\t\twant code: \"%#v\"", st.Code(), w.code) } - - gotLoc, err := s.Upsert(test.args.ctx, test.args.req) - if err := checkFunc(test.want, gotLoc, err); err != nil { - tt.Errorf("error = %v", err) + } else { + if uuid := gotRes.GetUuid(); w.wantUUID != uuid { + return errors.Errorf("got uuid: \"%#v\",\n\t\t\t\twant uuid: \"%#v\"", uuid, w.wantUUID) } - }) + } + return nil } -} -func Test_server_StreamUpsert(t *testing.T) { - t.Parallel() - type args struct { - stream vald.Upsert_StreamUpsertServer + const ( + defaultInsertNum = 1000 + dimension = 128 + ) + + utf8Str := "ใ“ใ‚“ใซใกใฏ" + eucjpStr, err := conv.Utf8ToEucjp(utf8Str) + if err != nil { + t.Error(err) } - type fields struct { - name string - ip string - ngt service.NGT - eg errgroup.Group - streamConcurrency int + sjisStr, err := conv.Utf8ToSjis(utf8Str) + if err != nil { + t.Error(err) } - type want struct { - err error + + defaultUpsertConfig := &payload.Upsert_Config{ + SkipStrictExistCheck: true, } - type test struct { - name string - args args - fields fields - want want - checkFunc func(want, error) error - beforeFunc func(args) - afterFunc func(args) + defaultInsertConfig := &payload.Insert_Config{ + SkipStrictExistCheck: true, } - defaultCheckFunc := func(w want, err error) error { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + beforeFunc := func(objectType string, insertNum int) func(args) (Server, error) { + cfg := &config.NGT{ + Dimension: dimension, + DistanceType: ngt.L2.String(), + ObjectType: objectType, + CreationEdgeSize: 60, + SearchEdgeSize: 20, + KVSDB: &config.KVSDB{ + Concurrency: 10, + }, + VQueue: &config.VQueue{ + InsertBufferPoolSize: 1000, + DeleteBufferPoolSize: 1000, + }, + } + + return func(a args) (Server, error) { + var overwriteID []string + if a.indexID != "" { + overwriteID = []string{ + a.indexID, + } + } + var overwriteVec [][]float32 + if a.indexVector != nil { + overwriteVec = [][]float32{ + a.indexVector, + } + } + return buildIndex(a.ctx, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, cfg, nil, overwriteID, overwriteVec) } - return nil } /* @@ -203,9 +165,9 @@ func Test_server_StreamUpsert(t *testing.T) { - case 3.4: success upsert with s-jis ID from utf-8 index - case 3.5: success upsert with s-jis ID from s-jis index - case 3.6: success upsert with s-jis ID from euc-jp index - - case 3.4: success upsert with euc-jp ID from utf-8 index - - case 3.5: success upsert with euc-jp ID from s-jis index - - case 3.6: success upsert with euc-jp ID from euc-jp index + - case 3.7: success upsert with euc-jp ID from utf-8 index + - case 3.8: success upsert with euc-jp ID from s-jis index + - case 3.9: success upsert with euc-jp ID from euc-jp index - case 4.1: success upsert with ๐Ÿ˜€ as duplicated ID - case 4.2: success upsert with ๐Ÿ˜€ as new ID - case 4.3: success upsert to empty index with ๐Ÿ˜€ as new ID @@ -247,16 +209,1413 @@ func Test_server_StreamUpsert(t *testing.T) { - case 1.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is true - case 1.2: success upsert with one different vector, duplicated ID and SkipStrictExistsCheck is true - case 1.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is true - - case 2.1: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is true - - case 2.2: success upsert with one different vector, new ID and SkipStrictExistsCheck is true - - case 2.3: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is true - - case 3.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false - - case 3.2: success upsert with one different vector, duplicated ID and SkipStrictExistsCheck is false - - case 3.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is false - - case 4.1: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is false - - case 4.2: success upsert with one different vector, new ID and SkipStrictExistsCheck is false - - case 4.3: success upsert with one duplicated vector, new ID and SkipStrictExistCheck is false + - case 1.4: success upsert with one different vector, different ID and SkipStrictExistsCheck is true + - case 2.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false + - case 2.2: success upsert with one different vector, duplicated ID and SkipStrictExistsCheck is false + - case 2.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is false + - case 2.4: success upsert with one different vector, different ID and SkipStrictExistsCheck is false */ + tests := []test{ + { + name: "Equivalent Class Testing case 1.1: success upsert with new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Equivalent Class Testing case 1.2: success upsert with existent ID", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Equivalent Class Testing case 2.1: fail upsert with one different dimension vector (type: uint8)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.ConvertVectorsUint8ToFloat32(vector.GaussianDistributedUint8VectorGenerator(1, dimension+1))[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + code: codes.InvalidArgument, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), defaultInsertNum), + }, + { + name: "Equivalent Class Testint case 2.2: fail upsert with one different dimension vector (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension+1)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + code: codes.InvalidArgument, + }, + }, + + { + name: "Boundary Value Testing case 1.1: fail upsert with \"\" as ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + code: codes.InvalidArgument, + }, + }, + { + name: "Boundary Value Testing case 1.2: fail upsert to empty index with \"\" as ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + code: codes.InvalidArgument, + }, + }, + { + name: "Boundary Value Testing case 2.1: success upsert with ^@ as duplicated ID", + args: args{ + ctx: ctx, + indexID: string([]byte{0}), + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{0}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{0}), + }, + }, + { + name: "Boundary Value Testing case 2.2: success upsert with ^@ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{0}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{0}), + }, + }, + { + name: "Boundary Value Testing case 2.3: success upsert to empty index with ^@ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{0}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: string([]byte{0}), + }, + }, + { + name: "Boundary Value Testing case 2.4: success upsert with ^I as duplicated ID", + args: args{ + ctx: ctx, + indexID: "\t", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\t", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\t", + }, + }, + { + name: "Boundary Value Testing case 2.5: success upsert with ^I as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\t", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\t", + }, + }, + { + name: "Boundary Value Testing case 2.6: success upsert to empty index with ^I as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\t", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "\t", + }, + }, + { + name: "Boundary Value Testing case 2.7: success upsert with ^J as duplicated ID", + args: args{ + ctx: ctx, + indexID: "\n", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\n", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\n", + }, + }, + { + name: "Boundary Value Testing case 2.8: success upsert with ^J as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\n", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\n", + }, + }, + { + name: "Boundary Value Testing case 2.9: success upsert to empty index with ^J as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\n", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "\n", + }, + }, + { + name: "Boundary Value Testing case 2.10: success upsert with ^M as duplicated ID", + args: args{ + ctx: ctx, + indexID: "\r", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\r", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\r", + }, + }, + { + name: "Boundary Value Testing case 2.11: success upsert with ^M as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\r", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "\r", + }, + }, + { + name: "Boundary Value Testing case 2.12: success upsert to empty index with ^M as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "\r", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "\r", + }, + }, + { + name: "Boundary Value Testing case 2.13: success upsert with ^[ as duplicated ID", + args: args{ + ctx: ctx, + indexID: string([]byte{27}), + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{27}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{27}), + }, + }, + { + name: "Boundary Value Testing case 2.14: success upsert with ^[ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{27}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{27}), + }, + }, + { + name: "Boundary Value Testing case 2.15: success upsert to empty index with ^[ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{27}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: string([]byte{27}), + }, + }, + { + name: "Boundary Value Testing case 2.16: success upsert with ^? as duplicated ID", + args: args{ + ctx: ctx, + indexID: string([]byte{127}), + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{127}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{127}), + }, + }, + { + name: "Boundary Value Testing case 2.17: success upsert with ^? as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{127}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: string([]byte{127}), + }, + }, + { + name: "Boundary Value Testing case 2.18: success upsert to empty index with ^? as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: string([]byte{127}), + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: string([]byte{127}), + }, + }, + { + name: "Boundary Value Testing case 3.1: success upsert with utf-8 ID from utf-8 index", + args: args{ + ctx: ctx, + indexID: utf8Str, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: utf8Str, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: utf8Str, + }, + }, + { + name: "Boundary Value Testing case 3.2: success upsert with utf-8 ID from s-jis index", + args: args{ + ctx: ctx, + indexID: sjisStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: utf8Str, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: utf8Str, + }, + }, + { + name: "Boundary Value Testing case 3.3: success upsert with utf-8 ID from euc-jp index", + args: args{ + ctx: ctx, + indexID: eucjpStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: utf8Str, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: utf8Str, + }, + }, + { + name: "Boundary Value Testing case 3.4: success upsert with s-jis ID from utf-8 index", + args: args{ + ctx: ctx, + indexID: utf8Str, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: sjisStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: sjisStr, + }, + }, + { + name: "Boundary Value Testing case 3.5: success upsert with s-jis ID from s-jis index", + args: args{ + ctx: ctx, + indexID: sjisStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: sjisStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: sjisStr, + }, + }, + { + name: "Boundary Value Testing case 3.6: success upsert with s-jis ID from euc-jp index", + args: args{ + ctx: ctx, + indexID: eucjpStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: sjisStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: sjisStr, + }, + }, + { + name: "Boundary Value Testing case 3.7: success upsert with euc-jp ID from utf-8 index", + args: args{ + ctx: ctx, + indexID: utf8Str, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: eucjpStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: eucjpStr, + }, + }, + { + name: "Boundary Value Testing case 3.8: success upsert with euc-jp ID from s-jis index", + args: args{ + ctx: ctx, + indexID: sjisStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: eucjpStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: eucjpStr, + }, + }, + { + name: "Boundary Value Testing case 3.9: success upsert with euc-jp ID from euc-jp index", + args: args{ + ctx: ctx, + indexID: eucjpStr, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: eucjpStr, + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: eucjpStr, + }, + }, + { + name: "Boundary Value Testing case 4.1: success upsert with ๐Ÿ˜€ as duplicated ID", + args: args{ + ctx: ctx, + indexID: "๐Ÿ˜€", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "๐Ÿ˜€", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "๐Ÿ˜€", + }, + }, + { + name: "Boundary Value Testing case 4.2: success upsert with ๐Ÿ˜€ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "๐Ÿ˜€", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "๐Ÿ˜€", + }, + }, + { + name: "Boundary Value Testing case 4.3: success upsert to empty index with ๐Ÿ˜€ as new ID", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "๐Ÿ˜€", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "๐Ÿ˜€", + }, + }, + { + name: "Boundary Value Testing case 5.1: success upsert with one 0 value vector with duplicated ID (type: uint8)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.2: success upsert with one 0 value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.3: success upsert to empty index with one 0 value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.4: success upsert with one +0 value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, 0), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.5: success upsert with one +0 value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, 0), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.6: success upsert to empty index with one +0 value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, 0), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.7: success upsert with one -0 value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Copysign(0, -1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.8: success upsert with one -0 value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Copysign(0, -1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 5.9: success upsert to empty index with one -0 value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Copysign(0, -1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.1: success upsert with one min value vector with duplicated ID (type: uint8)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.2: success upsert with one min value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.3: success upsert to empty index with one min value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(uint8(0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.4: success upsert with one min value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, -math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.5: success upsert with one min value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, -math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 6.6: success upsert with one min value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, -math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.1: success upsert with one max value vector with ID (type: uint8)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.MaxUint8)), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.2: success upsert with one max value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.MaxUint8)), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.3: success upsert to empty index with one max value vector with new ID (type: uint8)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.MaxUint8)), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.4: success upsert with one max value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.5: success upsert with one max value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 7.6: success upsert to empty index with one max value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, math.MaxFloat32), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 8.1: success upsert with one NaN value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.NaN())), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 8.2: success upsert with one NaN value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.NaN())), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 8.3: success upsert to empty index with one NaN value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.NaN())), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.1: success upsert with one +inf value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.2: success upsert with one +inf value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.3: success upsert to empty index with one +inf value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.4: success upsert with one -inf value vector with duplicated ID (type: float32)", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(-1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.5: success upsert with one -inf value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(-1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 9.6: success upsert to empty index with one -inf value vector with new ID (type: float32)", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(-1.0))), + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + wantUUID: "test", + }, + }, + { + name: "Boundary Value Testing case 10.1: fail upsert with one nil vector", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: nil, + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + code: codes.InvalidArgument, + }, + }, + { + name: "Boundary Value Testing case 10.2: fail upsert to empty with one nil vector", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: nil, + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + code: codes.InvalidArgument, + }, + }, + { + name: "Boundary Value Testing case 11.1: fail upsert with one empty vector", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: []float32{}, + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + code: codes.InvalidArgument, + }, + }, + { + name: "Boundary Value Testing case 11.2: fail upsert to empty index with one empty vector", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: []float32{}, + }, + Config: defaultUpsertConfig, + }, + }, + beforeFunc: beforeFunc(ngt.Float.String(), 0), + want: want{ + code: codes.InvalidArgument, + }, + }, + + { + name: "Decision Table Testing case 1.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is true", + args: func() args { + vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] + return args{ + ctx: ctx, + indexID: "test", + indexVector: vector, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector, + }, + Config: defaultUpsertConfig, + }, + } + }(), + want: want{ + code: codes.AlreadyExists, + }, + }, + { + name: "Decision Table Testing case 1.2: success upsert with one different vector, duplicated ID and SkipStrictExistCheck is true", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Decision Table Testing case 1.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is true", + args: func() args { + vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] + return args{ + ctx: ctx, + indexID: "test", + indexVector: vector, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "uuid-2", // the first uuid is overwritten, so use the second one + Vector: vector, + }, + Config: defaultUpsertConfig, + }, + } + }(), + want: want{ + wantUUID: "uuid-2", + }, + }, + { + name: "Decision Table Testing case 1.4: success upsert with one different vector, different ID and SkipStrictExistCheck is true", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: defaultUpsertConfig, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Decision Table Testing case 2.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false", + args: func() args { + vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] + return args{ + ctx: ctx, + indexID: "test", + indexVector: vector, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector, + }, + Config: &payload.Upsert_Config{ + SkipStrictExistCheck: false, + }, + }, + } + }(), + want: want{ + code: codes.AlreadyExists, + }, + }, + { + name: "Decision Table Testing case 2.2: success upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false", + args: args{ + ctx: ctx, + indexID: "test", + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: &payload.Upsert_Config{ + SkipStrictExistCheck: false, + }, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + { + name: "Decision Table Testing case 2.3: success upsert with one duplicated vector, different ID and SkipStrictExistCheck is false", + args: func() args { + vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] + return args{ + ctx: ctx, + indexID: "test", + indexVector: vector, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "uuid-2", // the first uuid is overwritten, so use the second one + Vector: vector, + }, + Config: &payload.Upsert_Config{ + SkipStrictExistCheck: false, + }, + }, + } + }(), + want: want{ + wantUUID: "uuid-2", + }, + }, + { + name: "Decision Table Testing case 2.4: success upsert with one different vector, different ID and SkipStrictExistCheck is false", + args: args{ + ctx: ctx, + req: &payload.Upsert_Request{ + Vector: &payload.Object_Vector{ + Id: "test", + Vector: vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0], + }, + Config: &payload.Upsert_Config{ + SkipStrictExistCheck: false, + }, + }, + }, + want: want{ + wantUUID: "test", + }, + }, + } + + for _, tc := range tests { + test := tc + t.Run(test.name, func(tt *testing.T) { + tt.Parallel() + defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + if test.beforeFunc == nil { + test.beforeFunc = beforeFunc(ngt.Float.String(), defaultInsertNum) + } + s, err := test.beforeFunc(test.args) + if err != nil { + tt.Errorf("error = %v", err) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + checkFunc := test.checkFunc + if test.checkFunc == nil { + checkFunc = defaultCheckFunc + } + + gotLoc, err := s.Upsert(test.args.ctx, test.args.req) + if err := checkFunc(test.want, gotLoc, err); err != nil { + tt.Errorf("error = %v", err) + } + }) + } +} + +func Test_server_StreamUpsert(t *testing.T) { + t.Parallel() + type args struct { + stream vald.Upsert_StreamUpsertServer + } + type fields struct { + name string + ip string + ngt service.NGT + eg errgroup.Group + streamConcurrency int + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err) + } + return nil + } + tests := []test{ // TODO test cases /* From f69d1e53503bb251d10ac8974e5b23e29addb4c7 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Thu, 9 Jun 2022 16:40:10 +0900 Subject: [PATCH 3/6] Update pkg/agent/core/ngt/handler/grpc/upsert_test.go Co-authored-by: Kiichiro YUKAWA --- pkg/agent/core/ngt/handler/grpc/upsert_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index afedb84408..f104064777 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -98,7 +98,7 @@ func Test_server_Upsert(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - beforeFunc := func(objectType string, insertNum int) func(args) (Server, error) { + defaultBeforeFunc := func(objectType string, insertNum int) func(args) (Server, error) { cfg := &config.NGT{ Dimension: dimension, DistanceType: ngt.L2.String(), From 2253d1bc8c25ba45f148e06c8bce0addda06aa4a Mon Sep 17 00:00:00 2001 From: vankichi Date: Fri, 10 Jun 2022 22:12:16 +0900 Subject: [PATCH 4/6] :white_check_mark: fix build error and rafactor args val Signed-off-by: vankichi --- .../core/ngt/handler/grpc/upsert_test.go | 326 +++++++++++------- 1 file changed, 203 insertions(+), 123 deletions(-) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index f104064777..ac1e3fdcdf 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -42,11 +42,16 @@ func Test_server_Upsert(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + // optIdx is used for additional vector before upsert test. + type optIdx struct { + id string + vec []float32 + } + type args struct { - ctx context.Context - indexID string - indexVector []float32 - req *payload.Upsert_Request + ctx context.Context + optIdx optIdx + req *payload.Upsert_Request } type want struct { code codes.Code @@ -57,7 +62,7 @@ func Test_server_Upsert(t *testing.T) { args args want want checkFunc func(want, *payload.Object_Location, error) error - beforeFunc func(args) (Server, error) + beforeFunc func(context.Context, optIdx) (Server, error) afterFunc func(args) } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { @@ -98,7 +103,7 @@ func Test_server_Upsert(t *testing.T) { defaultInsertConfig := &payload.Insert_Config{ SkipStrictExistCheck: true, } - defaultBeforeFunc := func(objectType string, insertNum int) func(args) (Server, error) { + defaultBeforeFunc := func(objectType string, insertNum int) func(context.Context, optIdx) (Server, error) { cfg := &config.NGT{ Dimension: dimension, DistanceType: ngt.L2.String(), @@ -114,20 +119,20 @@ func Test_server_Upsert(t *testing.T) { }, } - return func(a args) (Server, error) { + return func(ctx context.Context, opt optIdx) (Server, error) { var overwriteID []string - if a.indexID != "" { + if opt.id != "" { overwriteID = []string{ - a.indexID, + opt.id, } } var overwriteVec [][]float32 - if a.indexVector != nil { + if opt.vec != nil { overwriteVec = [][]float32{ - a.indexVector, + opt.vec, } } - return buildIndex(a.ctx, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, cfg, nil, overwriteID, overwriteVec) + return buildIndex(ctx, request.Float, vector.Gaussian, insertNum, defaultInsertConfig, cfg, nil, overwriteID, overwriteVec) } } @@ -235,8 +240,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Equivalent Class Testing case 1.2: success upsert with existent ID", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -252,8 +259,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Equivalent Class Testing case 2.1: fail upsert with one different dimension vector (type: uint8)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -265,13 +274,15 @@ func Test_server_Upsert(t *testing.T) { want: want{ code: codes.InvalidArgument, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), defaultInsertNum), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), defaultInsertNum), }, { name: "Equivalent Class Testint case 2.2: fail upsert with one different dimension vector (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -313,7 +324,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ code: codes.InvalidArgument, }, @@ -321,8 +332,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.1: success upsert with ^@ as duplicated ID", args: args{ - ctx: ctx, - indexID: string([]byte{0}), + ctx: ctx, + optIdx: optIdx{ + id: string([]byte{0}), + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{0}), @@ -363,7 +376,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: string([]byte{0}), }, @@ -371,8 +384,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.4: success upsert with ^I as duplicated ID", args: args{ - ctx: ctx, - indexID: "\t", + ctx: ctx, + optIdx: optIdx{ + id: "\t", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\t", @@ -413,7 +428,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "\t", }, @@ -421,8 +436,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.7: success upsert with ^J as duplicated ID", args: args{ - ctx: ctx, - indexID: "\n", + ctx: ctx, + optIdx: optIdx{ + id: "\n", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\n", @@ -463,7 +480,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "\n", }, @@ -471,8 +488,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.10: success upsert with ^M as duplicated ID", args: args{ - ctx: ctx, - indexID: "\r", + ctx: ctx, + optIdx: optIdx{ + id: "\r", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\r", @@ -513,7 +532,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "\r", }, @@ -521,8 +540,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.13: success upsert with ^[ as duplicated ID", args: args{ - ctx: ctx, - indexID: string([]byte{27}), + ctx: ctx, + optIdx: optIdx{ + id: string([]byte{27}), + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{27}), @@ -563,7 +584,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: string([]byte{27}), }, @@ -571,8 +592,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.16: success upsert with ^? as duplicated ID", args: args{ - ctx: ctx, - indexID: string([]byte{127}), + ctx: ctx, + optIdx: optIdx{ + id: string([]byte{127}), + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{127}), @@ -613,7 +636,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: string([]byte{127}), }, @@ -621,8 +644,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.1: success upsert with utf-8 ID from utf-8 index", args: args{ - ctx: ctx, - indexID: utf8Str, + ctx: ctx, + optIdx: optIdx{ + id: utf8Str, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: utf8Str, @@ -638,8 +663,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.2: success upsert with utf-8 ID from s-jis index", args: args{ - ctx: ctx, - indexID: sjisStr, + ctx: ctx, + optIdx: optIdx{ + id: sjisStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: utf8Str, @@ -655,8 +682,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.3: success upsert with utf-8 ID from euc-jp index", args: args{ - ctx: ctx, - indexID: eucjpStr, + ctx: ctx, + optIdx: optIdx{ + id: eucjpStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: utf8Str, @@ -672,8 +701,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.4: success upsert with s-jis ID from utf-8 index", args: args{ - ctx: ctx, - indexID: utf8Str, + ctx: ctx, + optIdx: optIdx{ + id: utf8Str, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: sjisStr, @@ -689,8 +720,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.5: success upsert with s-jis ID from s-jis index", args: args{ - ctx: ctx, - indexID: sjisStr, + ctx: ctx, + optIdx: optIdx{ + id: sjisStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: sjisStr, @@ -706,8 +739,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.6: success upsert with s-jis ID from euc-jp index", args: args{ - ctx: ctx, - indexID: eucjpStr, + ctx: ctx, + optIdx: optIdx{ + id: eucjpStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: sjisStr, @@ -723,8 +758,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.7: success upsert with euc-jp ID from utf-8 index", args: args{ - ctx: ctx, - indexID: utf8Str, + ctx: ctx, + optIdx: optIdx{ + id: utf8Str, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: eucjpStr, @@ -740,8 +777,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.8: success upsert with euc-jp ID from s-jis index", args: args{ - ctx: ctx, - indexID: sjisStr, + ctx: ctx, + optIdx: optIdx{ + id: sjisStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: eucjpStr, @@ -757,8 +796,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.9: success upsert with euc-jp ID from euc-jp index", args: args{ - ctx: ctx, - indexID: eucjpStr, + ctx: ctx, + optIdx: optIdx{ + id: eucjpStr, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: eucjpStr, @@ -774,8 +815,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 4.1: success upsert with ๐Ÿ˜€ as duplicated ID", args: args{ - ctx: ctx, - indexID: "๐Ÿ˜€", + ctx: ctx, + optIdx: optIdx{ + id: "๐Ÿ˜€", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "๐Ÿ˜€", @@ -816,7 +859,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "๐Ÿ˜€", }, @@ -824,8 +867,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.1: success upsert with one 0 value vector with duplicated ID (type: uint8)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -834,7 +879,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -851,7 +896,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -868,7 +913,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 0), want: want{ wantUUID: "test", }, @@ -876,8 +921,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.4: success upsert with one +0 value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -918,7 +965,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -926,8 +973,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.7: success upsert with one -0 value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -968,7 +1017,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -976,8 +1025,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.1: success upsert with one min value vector with duplicated ID (type: uint8)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -986,7 +1037,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -1003,7 +1054,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -1020,7 +1071,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 0), want: want{ wantUUID: "test", }, @@ -1028,8 +1079,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.4: success upsert with one min value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1070,7 +1123,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -1078,8 +1131,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.1: success upsert with one max value vector with ID (type: uint8)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1088,7 +1143,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -1105,7 +1160,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 1000), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 1000), want: want{ wantUUID: "test", }, @@ -1122,7 +1177,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Uint8.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), 0), want: want{ wantUUID: "test", }, @@ -1130,8 +1185,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.4: success upsert with one max value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1172,7 +1229,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -1180,8 +1237,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 8.1: success upsert with one NaN value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1222,7 +1281,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -1230,8 +1289,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.1: success upsert with one +inf value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1272,7 +1333,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -1280,8 +1341,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.4: success upsert with one -inf value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1316,13 +1379,12 @@ func Test_server_Upsert(t *testing.T) { ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ - Id: "test", - Vector: vector.GenSameValueVec(dimension, float32(math.Inf(-1.0))), + Id: "test", }, Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ wantUUID: "test", }, @@ -1330,8 +1392,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 10.1: fail upsert with one nil vector", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1356,7 +1420,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ code: codes.InvalidArgument, }, @@ -1364,8 +1428,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 11.1: fail upsert with one empty vector", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1381,8 +1447,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 11.2: fail upsert to empty index with one empty vector", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1391,7 +1459,7 @@ func Test_server_Upsert(t *testing.T) { Config: defaultUpsertConfig, }, }, - beforeFunc: beforeFunc(ngt.Float.String(), 0), + beforeFunc: defaultBeforeFunc(ngt.Float.String(), 0), want: want{ code: codes.InvalidArgument, }, @@ -1402,9 +1470,11 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, - indexID: "test", - indexVector: vector, + ctx: ctx, + optIdx: optIdx{ + id: "test", + vec: vector, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1421,8 +1491,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 1.2: success upsert with one different vector, duplicated ID and SkipStrictExistCheck is true", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1440,9 +1512,11 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, - indexID: "test", - indexVector: vector, + ctx: ctx, + optIdx: optIdx{ + id: "test", + vec: vector, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "uuid-2", // the first uuid is overwritten, so use the second one @@ -1477,9 +1551,11 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, - indexID: "test", - indexVector: vector, + ctx: ctx, + optIdx: optIdx{ + id: "test", + vec: vector, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1498,8 +1574,10 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 2.2: success upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false", args: args{ - ctx: ctx, - indexID: "test", + ctx: ctx, + optIdx: optIdx{ + id: "test", + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1519,9 +1597,11 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, - indexID: "test", - indexVector: vector, + ctx: ctx, + optIdx: optIdx{ + id: "test", + vec: vector, + }, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "uuid-2", // the first uuid is overwritten, so use the second one @@ -1563,9 +1643,9 @@ func Test_server_Upsert(t *testing.T) { tt.Parallel() defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) if test.beforeFunc == nil { - test.beforeFunc = beforeFunc(ngt.Float.String(), defaultInsertNum) + test.beforeFunc = defaultBeforeFunc(ngt.Float.String(), defaultInsertNum) } - s, err := test.beforeFunc(test.args) + s, err := test.beforeFunc(test.args.ctx, test.args.optIdx) if err != nil { tt.Errorf("error = %v", err) } From 1a1f5d87fca485e749f1b5104a96e95239214645 Mon Sep 17 00:00:00 2001 From: vankichi Date: Mon, 13 Jun 2022 10:43:34 +0900 Subject: [PATCH 5/6] :white_check_mark: fix test error Signed-off-by: vankichi --- pkg/agent/core/ngt/handler/grpc/upsert_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index ac1e3fdcdf..274a88294d 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -1379,7 +1379,8 @@ func Test_server_Upsert(t *testing.T) { ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ - Id: "test", + Id: "test", + Vector: vector.GenSameValueVec(dimension, float32(math.Inf(-1.0))), }, Config: defaultUpsertConfig, }, From 225c74515c04db46dea9a4bcd2a7fe14c1701107 Mon Sep 17 00:00:00 2001 From: vankichi Date: Mon, 13 Jun 2022 18:04:25 +0900 Subject: [PATCH 6/6] :recycle: fix race condition test error Signed-off-by: vankichi --- .../core/ngt/handler/grpc/upsert_test.go | 97 ++----------------- 1 file changed, 7 insertions(+), 90 deletions(-) diff --git a/pkg/agent/core/ngt/handler/grpc/upsert_test.go b/pkg/agent/core/ngt/handler/grpc/upsert_test.go index 274a88294d..d721be3fc1 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert_test.go @@ -39,9 +39,6 @@ import ( func Test_server_Upsert(t *testing.T) { t.Parallel() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - // optIdx is used for additional vector before upsert test. type optIdx struct { id string @@ -49,7 +46,6 @@ func Test_server_Upsert(t *testing.T) { } type args struct { - ctx context.Context optIdx optIdx req *payload.Upsert_Request } @@ -63,7 +59,7 @@ func Test_server_Upsert(t *testing.T) { want want checkFunc func(want, *payload.Object_Location, error) error beforeFunc func(context.Context, optIdx) (Server, error) - afterFunc func(args) + afterFunc func() } defaultCheckFunc := func(w want, gotRes *payload.Object_Location, err error) error { if err != nil { @@ -224,7 +220,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Equivalent Class Testing case 1.1: success upsert with new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -240,7 +235,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Equivalent Class Testing case 1.2: success upsert with existent ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -259,7 +253,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Equivalent Class Testing case 2.1: fail upsert with one different dimension vector (type: uint8)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -277,9 +270,8 @@ func Test_server_Upsert(t *testing.T) { beforeFunc: defaultBeforeFunc(ngt.Uint8.String(), defaultInsertNum), }, { - name: "Equivalent Class Testint case 2.2: fail upsert with one different dimension vector (type: float32)", + name: "Equivalent Class Testing case 2.2: fail upsert with one different dimension vector (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -295,11 +287,9 @@ func Test_server_Upsert(t *testing.T) { code: codes.InvalidArgument, }, }, - { name: "Boundary Value Testing case 1.1: fail upsert with \"\" as ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "", @@ -315,7 +305,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 1.2: fail upsert to empty index with \"\" as ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "", @@ -332,7 +321,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.1: success upsert with ^@ as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: string([]byte{0}), }, @@ -351,7 +339,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.2: success upsert with ^@ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{0}), @@ -367,7 +354,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.3: success upsert to empty index with ^@ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{0}), @@ -384,7 +370,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.4: success upsert with ^I as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: "\t", }, @@ -403,7 +388,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.5: success upsert with ^I as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\t", @@ -419,7 +403,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.6: success upsert to empty index with ^I as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\t", @@ -436,7 +419,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.7: success upsert with ^J as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: "\n", }, @@ -455,7 +437,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.8: success upsert with ^J as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\n", @@ -471,7 +452,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.9: success upsert to empty index with ^J as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\n", @@ -488,7 +468,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.10: success upsert with ^M as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: "\r", }, @@ -507,7 +486,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.11: success upsert with ^M as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\r", @@ -523,7 +501,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.12: success upsert to empty index with ^M as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "\r", @@ -540,7 +517,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.13: success upsert with ^[ as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: string([]byte{27}), }, @@ -559,7 +535,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.14: success upsert with ^[ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{27}), @@ -575,7 +550,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.15: success upsert to empty index with ^[ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{27}), @@ -592,7 +566,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.16: success upsert with ^? as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: string([]byte{127}), }, @@ -611,7 +584,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.17: success upsert with ^? as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{127}), @@ -627,7 +599,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 2.18: success upsert to empty index with ^? as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: string([]byte{127}), @@ -644,7 +615,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.1: success upsert with utf-8 ID from utf-8 index", args: args{ - ctx: ctx, optIdx: optIdx{ id: utf8Str, }, @@ -663,7 +633,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.2: success upsert with utf-8 ID from s-jis index", args: args{ - ctx: ctx, optIdx: optIdx{ id: sjisStr, }, @@ -682,7 +651,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.3: success upsert with utf-8 ID from euc-jp index", args: args{ - ctx: ctx, optIdx: optIdx{ id: eucjpStr, }, @@ -701,7 +669,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.4: success upsert with s-jis ID from utf-8 index", args: args{ - ctx: ctx, optIdx: optIdx{ id: utf8Str, }, @@ -720,7 +687,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.5: success upsert with s-jis ID from s-jis index", args: args{ - ctx: ctx, optIdx: optIdx{ id: sjisStr, }, @@ -739,7 +705,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.6: success upsert with s-jis ID from euc-jp index", args: args{ - ctx: ctx, optIdx: optIdx{ id: eucjpStr, }, @@ -758,7 +723,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.7: success upsert with euc-jp ID from utf-8 index", args: args{ - ctx: ctx, optIdx: optIdx{ id: utf8Str, }, @@ -777,7 +741,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.8: success upsert with euc-jp ID from s-jis index", args: args{ - ctx: ctx, optIdx: optIdx{ id: sjisStr, }, @@ -796,7 +759,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 3.9: success upsert with euc-jp ID from euc-jp index", args: args{ - ctx: ctx, optIdx: optIdx{ id: eucjpStr, }, @@ -815,7 +777,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 4.1: success upsert with ๐Ÿ˜€ as duplicated ID", args: args{ - ctx: ctx, optIdx: optIdx{ id: "๐Ÿ˜€", }, @@ -834,7 +795,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 4.2: success upsert with ๐Ÿ˜€ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "๐Ÿ˜€", @@ -850,7 +810,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 4.3: success upsert to empty index with ๐Ÿ˜€ as new ID", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "๐Ÿ˜€", @@ -867,7 +826,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.1: success upsert with one 0 value vector with duplicated ID (type: uint8)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -887,7 +845,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.2: success upsert with one 0 value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -904,7 +861,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.3: success upsert to empty index with one 0 value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -921,7 +877,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.4: success upsert with one +0 value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -940,7 +895,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.5: success upsert with one +0 value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -956,7 +910,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.6: success upsert to empty index with one +0 value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -973,7 +926,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.7: success upsert with one -0 value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -992,7 +944,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.8: success upsert with one -0 value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1008,7 +959,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 5.9: success upsert to empty index with one -0 value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1025,7 +975,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.1: success upsert with one min value vector with duplicated ID (type: uint8)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1045,7 +994,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.2: success upsert with one min value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1062,7 +1010,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.3: success upsert to empty index with one min value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1079,7 +1026,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.4: success upsert with one min value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1098,7 +1044,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.5: success upsert with one min value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1114,7 +1059,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 6.6: success upsert with one min value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1131,7 +1075,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.1: success upsert with one max value vector with ID (type: uint8)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1151,7 +1094,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.2: success upsert with one max value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1168,7 +1110,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.3: success upsert to empty index with one max value vector with new ID (type: uint8)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1185,7 +1126,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.4: success upsert with one max value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1204,7 +1144,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.5: success upsert with one max value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1220,7 +1159,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 7.6: success upsert to empty index with one max value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1237,7 +1175,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 8.1: success upsert with one NaN value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1256,7 +1193,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 8.2: success upsert with one NaN value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1272,7 +1208,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 8.3: success upsert to empty index with one NaN value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1289,7 +1224,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.1: success upsert with one +inf value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1308,7 +1242,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.2: success upsert with one +inf value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1324,7 +1257,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.3: success upsert to empty index with one +inf value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1341,7 +1273,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.4: success upsert with one -inf value vector with duplicated ID (type: float32)", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1360,7 +1291,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.5: success upsert with one -inf value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1376,7 +1306,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 9.6: success upsert to empty index with one -inf value vector with new ID (type: float32)", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1393,7 +1322,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 10.1: fail upsert with one nil vector", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1412,7 +1340,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 10.2: fail upsert to empty with one nil vector", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1429,7 +1356,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 11.1: fail upsert with one empty vector", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1448,7 +1374,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Boundary Value Testing case 11.2: fail upsert to empty index with one empty vector", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1465,13 +1390,11 @@ func Test_server_Upsert(t *testing.T) { code: codes.InvalidArgument, }, }, - { name: "Decision Table Testing case 1.1: fail upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is true", args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, optIdx: optIdx{ id: "test", vec: vector, @@ -1492,7 +1415,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 1.2: success upsert with one different vector, duplicated ID and SkipStrictExistCheck is true", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1513,7 +1435,6 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, optIdx: optIdx{ id: "test", vec: vector, @@ -1534,7 +1455,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 1.4: success upsert with one different vector, different ID and SkipStrictExistCheck is true", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1552,7 +1472,6 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, optIdx: optIdx{ id: "test", vec: vector, @@ -1575,7 +1494,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 2.2: success upsert with one duplicated vector, duplicated ID and SkipStrictExistCheck is false", args: args{ - ctx: ctx, optIdx: optIdx{ id: "test", }, @@ -1598,7 +1516,6 @@ func Test_server_Upsert(t *testing.T) { args: func() args { vector := vector.GaussianDistributedFloat32VectorGenerator(1, dimension)[0] return args{ - ctx: ctx, optIdx: optIdx{ id: "test", vec: vector, @@ -1621,7 +1538,6 @@ func Test_server_Upsert(t *testing.T) { { name: "Decision Table Testing case 2.4: success upsert with one different vector, different ID and SkipStrictExistCheck is false", args: args{ - ctx: ctx, req: &payload.Upsert_Request{ Vector: &payload.Object_Vector{ Id: "test", @@ -1642,23 +1558,24 @@ func Test_server_Upsert(t *testing.T) { test := tc t.Run(test.name, func(tt *testing.T) { tt.Parallel() + ctx, cancel := context.WithCancel(context.Background()) defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) + defer cancel() if test.beforeFunc == nil { test.beforeFunc = defaultBeforeFunc(ngt.Float.String(), defaultInsertNum) } - s, err := test.beforeFunc(test.args.ctx, test.args.optIdx) + s, err := test.beforeFunc(ctx, test.args.optIdx) if err != nil { tt.Errorf("error = %v", err) } if test.afterFunc != nil { - defer test.afterFunc(test.args) + defer test.afterFunc() } checkFunc := test.checkFunc if test.checkFunc == nil { checkFunc = defaultCheckFunc } - - gotLoc, err := s.Upsert(test.args.ctx, test.args.req) + gotLoc, err := s.Upsert(ctx, test.args.req) if err := checkFunc(test.want, gotLoc, err); err != nil { tt.Errorf("error = %v", err) }