Skip to content

Commit

Permalink
Add test for GetObjectMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Nov 10, 2023
1 parent db46d0d commit 924903d
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/agent/core/ngt/handler/grpc/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ func (s *server) GetObjectMeta(ctx context.Context, id *payload.Object_VectorMet
}

Check warning on line 300 in pkg/agent/core/ngt/handler/grpc/object.go

View check run for this annotation

Codecov / codecov/patch

pkg/agent/core/ngt/handler/grpc/object.go#L297-L300

Added lines #L297 - L300 were not covered by tests
return nil, err
}
res.Id = uuid
res.Timestamp = ts
return res, nil
return &payload.Object_VectorMeta{
Id: uuid,
Timestamp: ts,
}, nil
}
114 changes: 113 additions & 1 deletion pkg/agent/core/ngt/handler/grpc/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ func Test_server_GetObject(t *testing.T) {
}
}

func Test_server_StreamGetObject(t *testing.T) {
func Test_server_StreamListObject(t *testing.T) {
t.Parallel()

defaultConfig := config.NGT{
Expand Down Expand Up @@ -1337,6 +1337,118 @@ func Test_server_StreamGetObject(t *testing.T) {
}
}

func Test_server_GetObjectMeta(t *testing.T) {
t.Parallel()

defaultConfig := config.NGT{
Dimension: 100,
DistanceType: "l2",
ObjectType: "float",
BulkInsertChunkSize: 10,
CreationEdgeSize: 20,
SearchEdgeSize: 10,
EnableProactiveGC: false,
EnableCopyOnWrite: false,
KVSDB: &config.KVSDB{
Concurrency: 10,
},
BrokenIndexHistoryLimit: 1,
}

setup := func(t *testing.T) (context.Context, Server) {
t.Helper()
ngt, err := service.New(&defaultConfig)
require.NoError(t, err)

ctx := context.Background()
eg, ectx := errgroup.New(ctx)
opts := []Option{
WithIP(net.LoadLocalIP()),
WithNGT(ngt),
WithErrGroup(eg),
}
s, err := New(opts...)
require.NoError(t, err)

return ectx, s
}

type test struct {
name string
testfunc func(t *testing.T)
}

tests := []test{
{
name: "succeeds to get object meta",
testfunc: func(t *testing.T) {
ectx, s := setup(t)

// insert and create `num` index
num := 42
req, err := request.GenMultiInsertReq(request.Float, vector.Gaussian, num, 100, &payload.Insert_Config{})
require.NoError(t, err)

_, err = s.MultiInsert(ectx, req)
require.NoError(t, err)

_, err = s.CreateIndex(ectx, &payload.Control_CreateIndexRequest{
PoolSize: uint32(len(req.Requests)),
})
require.NoError(t, err)

res, err := s.GetObjectMeta(ectx, &payload.Object_VectorMetaRequest{
Id: &payload.Object_ID{
Id: req.GetRequests()[0].GetVector().GetId(),
},
})
require.NoError(t, err)

require.Equal(t, req.GetRequests()[0].GetVector().GetId(), res.GetId())
},
},
{

name: "returns error when the given ID is invalid",
testfunc: func(t *testing.T) {
ectx, s := setup(t)

_, err := s.GetObjectMeta(ectx, &payload.Object_VectorMetaRequest{
Id: &payload.Object_ID{
Id: "",
},
})
require.Error(t, err)
},
},
{

name: "returns error when the given ID is not found",
testfunc: func(t *testing.T) {
ectx, s := setup(t)

_, err := s.GetObjectMeta(ectx, &payload.Object_VectorMetaRequest{
Id: &payload.Object_ID{
Id: "not exist ID",
},
})
require.Error(t, err)

st, _ := status.FromError(err)
require.Equal(t, codes.NotFound, st.Code())
},
},
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
test.testfunc(tt)
})
}
}

// NOT IMPLEMENTED BELOW
//
// func Test_server_StreamListObject(t *testing.T) {
Expand Down

0 comments on commit 924903d

Please sign in to comment.