Skip to content

Commit

Permalink
fix TestImportV2 unit case
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG committed Jan 23, 2025
1 parent d54abac commit 7287862
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 20 deletions.
8 changes: 3 additions & 5 deletions internal/datacoord/import_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/milvus-io/milvus/pkg/proto/datapb"
"github.com/milvus-io/milvus/pkg/proto/indexpb"
"github.com/milvus-io/milvus/pkg/proto/internalpb"
"github.com/milvus-io/milvus/pkg/proto/rootcoordpb"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/timerecord"
"github.com/milvus-io/milvus/pkg/util/tsoutil"
Expand Down Expand Up @@ -528,7 +529,6 @@ func TestImportCheckerCompaction(t *testing.T) {
catalog.EXPECT().ListImportJobs(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListPreImportTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListImportTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListSegments(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListIndexes(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListSegmentIndexes(mock.Anything).Return(nil, nil)
Expand All @@ -543,11 +543,9 @@ func TestImportCheckerCompaction(t *testing.T) {
imeta, err := NewImportMeta(context.TODO(), catalog)
assert.NoError(t, err)

meta, err := newMeta(context.TODO(), catalog, nil)
assert.NoError(t, err)

broker := broker2.NewMockBroker(t)

broker.EXPECT().ShowCollectionIDs(mock.Anything).Return(&rootcoordpb.ShowCollectionIDsResponse{}, nil)
meta, err := newMeta(context.TODO(), catalog, nil, broker)
sjm := NewMockStatsJobManager(t)
l0CompactionTrigger := NewMockTriggerManager(t)
l0CompactionTrigger.EXPECT().PauseL0SegmentCompacting(mock.Anything).Return().Maybe()
Expand Down
14 changes: 9 additions & 5 deletions internal/datacoord/import_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus/internal/datacoord/allocator"
"github.com/milvus-io/milvus/internal/datacoord/broker"
broker2 "github.com/milvus-io/milvus/internal/datacoord/broker"
"github.com/milvus-io/milvus/internal/json"
"github.com/milvus-io/milvus/internal/metastore/mocks"
mocks2 "github.com/milvus-io/milvus/internal/mocks"
Expand All @@ -41,6 +42,7 @@ import (
"github.com/milvus-io/milvus/pkg/proto/datapb"
"github.com/milvus-io/milvus/pkg/proto/indexpb"
"github.com/milvus-io/milvus/pkg/proto/internalpb"
"github.com/milvus-io/milvus/pkg/proto/rootcoordpb"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
"github.com/milvus-io/milvus/pkg/util/paramtable"
Expand Down Expand Up @@ -165,17 +167,18 @@ func TestImportUtil_NewImportTasksWithDataTt(t *testing.T) {
alloc.EXPECT().AllocID(mock.Anything).Return(rand.Int63(), nil)

catalog := mocks.NewDataCoordCatalog(t)
catalog.EXPECT().ListSegments(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListAnalyzeTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListIndexes(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListSegmentIndexes(mock.Anything).Return(nil, nil)
catalog.EXPECT().AddSegment(mock.Anything, mock.Anything).Return(nil)
catalog.EXPECT().ListAnalyzeTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListCompactionTask(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListPartitionStatsInfos(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListStatsTasks(mock.Anything).Return(nil, nil)

meta, err := newMeta(context.TODO(), catalog, nil)
broker := broker2.NewMockBroker(t)
broker.EXPECT().ShowCollectionIDs(mock.Anything).Return(&rootcoordpb.ShowCollectionIDsResponse{}, nil)
meta, err := newMeta(context.TODO(), catalog, nil, broker)
assert.NoError(t, err)

tasks, err := NewImportTasks(fileGroups, job, alloc, meta)
Expand Down Expand Up @@ -285,7 +288,6 @@ func TestImportUtil_AssembleRequestWithDataTt(t *testing.T) {
}

catalog := mocks.NewDataCoordCatalog(t)
catalog.EXPECT().ListSegments(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListChannelCheckpoint(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListIndexes(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListSegmentIndexes(mock.Anything).Return(nil, nil)
Expand All @@ -301,7 +303,9 @@ func TestImportUtil_AssembleRequestWithDataTt(t *testing.T) {
return id, id + n, nil
})

meta, err := newMeta(context.TODO(), catalog, nil)
broker := broker2.NewMockBroker(t)
broker.EXPECT().ShowCollectionIDs(mock.Anything).Return(&rootcoordpb.ShowCollectionIDsResponse{}, nil)
meta, err := newMeta(context.TODO(), catalog, nil, broker)
assert.NoError(t, err)
segment := &SegmentInfo{
SegmentInfo: &datapb.SegmentInfo{ID: 5, IsImporting: true},
Expand Down
9 changes: 9 additions & 0 deletions internal/datacoord/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import (
"github.com/milvus-io/milvus/internal/datacoord/allocator"
"github.com/milvus-io/milvus/internal/datacoord/broker"
"github.com/milvus-io/milvus/internal/datacoord/session"
"github.com/milvus-io/milvus/internal/distributed/streaming"
"github.com/milvus-io/milvus/internal/metastore/mocks"
"github.com/milvus-io/milvus/internal/metastore/model"
mocks2 "github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/mocks/distributed/mock_streaming"
"github.com/milvus-io/milvus/internal/types"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/mq/msgstream"
Expand Down Expand Up @@ -1440,6 +1442,13 @@ func TestImportV2(t *testing.T) {
catalog.EXPECT().ListPreImportTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().ListImportTasks(mock.Anything).Return(nil, nil)
catalog.EXPECT().SaveImportJob(mock.Anything, mock.Anything).Return(nil)
wal := mock_streaming.NewMockWALAccesser(t)
b := mock_streaming.NewMockBroadcast(t)
wal.EXPECT().Broadcast().Return(b)
b.EXPECT().BlockUntilResourceKeyAckOnce(mock.Anything, mock.Anything).Return(nil)
streaming.SetWALForTest(wal)
defer streaming.RecoverWALForTest()

s.importMeta, err = NewImportMeta(context.TODO(), catalog)
assert.NoError(t, err)
resp, err = s.GetImportProgress(ctx, &internalpb.GetImportProgressRequest{
Expand Down
21 changes: 15 additions & 6 deletions internal/datanode/msghandlerimpl/msg_handler_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
package msghandlerimpl

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/milvus-io/milvus/internal/distributed/streaming"
"github.com/milvus-io/milvus/internal/flushcommon/broker"
"github.com/milvus-io/milvus/internal/mocks/distributed/mock_streaming"
"github.com/milvus-io/milvus/pkg/util/paramtable"
)

func TestMsgHandlerImpl(t *testing.T) {
paramtable.Init()
ctx := context.Background()
b := broker.NewMockBroker(t)
m := NewMsgHandlerImpl(b)
assert.Panics(t, func() {
Expand All @@ -39,14 +45,17 @@ func TestMsgHandlerImpl(t *testing.T) {
assert.Panics(t, func() {
m.HandleManualFlush("", nil)
})
t.Run("HandleImport error", func(t *testing.T) {
b.EXPECT().ImportV2(mock.Anything, mock.Anything).Return(nil, assert.AnError).Once()
err := m.HandleImport(nil, "", nil)
assert.Error(t, err)
})
t.Run("HandleImport success", func(t *testing.T) {
wal := mock_streaming.NewMockWALAccesser(t)
bo := mock_streaming.NewMockBroadcast(t)
wal.EXPECT().Broadcast().Return(bo)
bo.EXPECT().Ack(mock.Anything, mock.Anything).Return(nil)
streaming.SetWALForTest(wal)
defer streaming.RecoverWALForTest()

b.EXPECT().ImportV2(mock.Anything, mock.Anything).Return(nil, assert.AnError).Once()
b.EXPECT().ImportV2(mock.Anything, mock.Anything).Return(nil, nil).Once()
err := m.HandleImport(nil, "", nil)
err := m.HandleImport(ctx, "", nil)
assert.NoError(t, err)
})
}
3 changes: 3 additions & 0 deletions internal/flushcommon/pipeline/flow_graph_dd_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ func (ddn *ddNode) Operate(in []Msg) []Msg {
}
case commonpb.MsgType_Import:
importMsg := msg.(*msgstream.ImportMsg)
if importMsg.GetCollectionID() != ddn.collectionID {
continue
}
logger := log.With(
zap.String("vchannel", ddn.Name()),
zap.Int32("msgType", int32(msg.Type())),
Expand Down
2 changes: 1 addition & 1 deletion internal/proxy/task_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (it *importTask) Execute(ctx context.Context) error {
log.Ctx(ctx).Warn("broadcast import msg failed", zap.Error(err))
return err
}
log.Ctx(ctx).Debug(
log.Ctx(ctx).Info(
"broadcast import msg success",
zap.Int64("jobID", jobID),
zap.Uint64("broadcastID", resp.BroadcastID),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/import/dynamic_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *BulkInsertSuite) testImportDynamicField() {
)

c := s.Cluster
ctx, cancel := context.WithTimeout(c.GetContext(), 120*time.Second)
ctx, cancel := context.WithTimeout(c.GetContext(), 240*time.Second)
defer cancel()

collectionName := "TestBulkInsert_B_" + funcutil.GenRandomStr()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/import/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *BulkInsertSuite) run() {
)

c := s.Cluster
ctx, cancel := context.WithTimeout(c.GetContext(), 120*time.Second)
ctx, cancel := context.WithTimeout(c.GetContext(), 240*time.Second)
defer cancel()

collectionName := "TestBulkInsert" + funcutil.GenRandomStr()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/import/partition_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *BulkInsertSuite) TestImportWithPartitionKey() {
)

c := s.Cluster
ctx, cancel := context.WithTimeout(c.GetContext(), 120*time.Second)
ctx, cancel := context.WithTimeout(c.GetContext(), 240*time.Second)
defer cancel()

collectionName := "TestBulkInsert_WithPartitionKey_" + funcutil.GenRandomStr()
Expand Down

0 comments on commit 7287862

Please sign in to comment.