mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
Fix the data race in the indexcoord unittest (#19515)
Signed-off-by: SimFG <bang.fu@zilliz.com> Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
parent
5550f883de
commit
7ca844ab99
@ -19,6 +19,7 @@ package indexcoord
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
@ -348,6 +349,8 @@ func NewRootCoordMock() *RootCoordMock {
|
||||
type DataCoordMock struct {
|
||||
types.DataCoord
|
||||
|
||||
FuncLock sync.RWMutex
|
||||
|
||||
CallInit func() error
|
||||
CallStart func() error
|
||||
CallGetComponentStates func(ctx context.Context) (*internalpb.ComponentStates, error)
|
||||
@ -370,7 +373,17 @@ func (dcm *DataCoordMock) GetComponentStates(ctx context.Context) (*internalpb.C
|
||||
return dcm.CallGetComponentStates(ctx)
|
||||
}
|
||||
|
||||
func (dcm *DataCoordMock) SetFunc(f func()) {
|
||||
dcm.FuncLock.Lock()
|
||||
defer dcm.FuncLock.Unlock()
|
||||
|
||||
f()
|
||||
}
|
||||
|
||||
func (dcm *DataCoordMock) GetSegmentInfo(ctx context.Context, req *datapb.GetSegmentInfoRequest) (*datapb.GetSegmentInfoResponse, error) {
|
||||
dcm.FuncLock.RLock()
|
||||
defer dcm.FuncLock.RUnlock()
|
||||
|
||||
return dcm.CallGetSegmentInfo(ctx, req)
|
||||
}
|
||||
func (dcm *DataCoordMock) AcquireSegmentLock(ctx context.Context, req *datapb.AcquireSegmentLockRequest) (*commonpb.Status, error) {
|
||||
|
||||
@ -211,13 +211,17 @@ func TestIndexCoord(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, resp.Status.ErrorCode, commonpb.ErrorCode_UnexpectedError)
|
||||
dcm.CallGetFlushedSegment = originFunc1
|
||||
dcm.CallGetSegmentInfo = func(ctx context.Context, req *datapb.GetSegmentInfoRequest) (*datapb.GetSegmentInfoResponse, error) {
|
||||
return nil, errors.New("mock error")
|
||||
}
|
||||
dcm.SetFunc(func() {
|
||||
dcm.CallGetSegmentInfo = func(ctx context.Context, req *datapb.GetSegmentInfoRequest) (*datapb.GetSegmentInfoResponse, error) {
|
||||
return nil, errors.New("mock error")
|
||||
}
|
||||
})
|
||||
resp, err = ic.DescribeIndex(ctx, req)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, resp.Status.ErrorCode, commonpb.ErrorCode_UnexpectedError)
|
||||
dcm.CallGetSegmentInfo = originFunc2
|
||||
dcm.SetFunc(func() {
|
||||
dcm.CallGetSegmentInfo = originFunc2
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("FlushedSegmentWatcher", func(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user