mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
fix: [2.5] improve error handling and unit tests for InitMetaCache function (#40324)
- issue: #40320 - pr: #40322 Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
parent
cc7d4ce399
commit
6ab8e84f1e
@ -361,7 +361,7 @@ func InitMetaCache(ctx context.Context, rootCoord types.RootCoordClient, queryCo
|
||||
|
||||
// The privilege info is a little more. And to get this info, the query operation of involving multiple table queries is required.
|
||||
resp, err := rootCoord.ListPolicy(ctx, &internalpb.ListPolicyRequest{})
|
||||
if err != nil {
|
||||
if err = merr.CheckRPCCall(resp, err); err != nil {
|
||||
log.Error("fail to init meta cache", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@ -385,6 +385,42 @@ func TestMetaCacheGetCollectionWithUpdate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestMetaCache_InitCache(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := mocks.NewMockRootCoordClient(t)
|
||||
queryCoord := mocks.NewMockQueryCoordClient(t)
|
||||
queryCoord.EXPECT().ShowCollections(mock.Anything, mock.Anything).Return(&querypb.ShowCollectionsResponse{}, nil).Maybe()
|
||||
rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything, mock.Anything).Return(&internalpb.ListPolicyResponse{Status: merr.Success()}, nil).Once()
|
||||
mgr := newShardClientMgr()
|
||||
err := InitMetaCache(ctx, rootCoord, queryCoord, mgr)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("failed to list policy", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := mocks.NewMockRootCoordClient(t)
|
||||
queryCoord := mocks.NewMockQueryCoordClient(t)
|
||||
rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything, mock.Anything).Return(
|
||||
&internalpb.ListPolicyResponse{Status: merr.Status(errors.New("mock list policy error"))},
|
||||
nil).Once()
|
||||
mgr := newShardClientMgr()
|
||||
err := InitMetaCache(ctx, rootCoord, queryCoord, mgr)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("rpc error", func(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := mocks.NewMockRootCoordClient(t)
|
||||
queryCoord := mocks.NewMockQueryCoordClient(t)
|
||||
rootCoord.EXPECT().ListPolicy(mock.Anything, mock.Anything, mock.Anything).Return(
|
||||
nil, errors.New("mock list policy rpc errorr")).Once()
|
||||
mgr := newShardClientMgr()
|
||||
err := InitMetaCache(ctx, rootCoord, queryCoord, mgr)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMetaCache_GetCollectionName(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
rootCoord := &MockRootCoordClientInterface{}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user