From b2931c7a8c878b69fdfdbf81566438e60b46de7e Mon Sep 17 00:00:00 2001 From: bufferflies <1045931706@qq.com> Date: Mon, 7 Aug 2023 12:53:57 +0800 Subject: [PATCH] pass ut Signed-off-by: bufferflies <1045931706@qq.com> --- server/cluster/cluster_worker_test.go | 17 +++++++++++++++++ server/grpc_service.go | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/cluster/cluster_worker_test.go b/server/cluster/cluster_worker_test.go index 16e90fa4b8d..35b7291e8b7 100644 --- a/server/cluster/cluster_worker_test.go +++ b/server/cluster/cluster_worker_test.go @@ -16,6 +16,7 @@ package cluster import ( "context" + "github.com/tikv/pd/pkg/schedule" "testing" "github.com/pingcap/kvproto/pkg/metapb" @@ -47,6 +48,7 @@ func TestReportSplit(t *testing.T) { _, opt, err := newTestScheduleConfig() re.NoError(err) cluster := newTestRaftCluster(ctx, mockid.NewIDAllocator(), opt, storage.NewStorageWithMemoryBackend(), core.NewBasicCluster()) + cluster.coordinator = schedule.NewCoordinator(cluster.ctx, cluster, nil) right := &metapb.Region{Id: 1, StartKey: []byte("a"), EndKey: []byte("c"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 1}} region := core.NewRegionInfo(right, right.Peers[0]) @@ -104,6 +106,7 @@ func TestReportBatchSplit(t *testing.T) { _, opt, err := newTestScheduleConfig() re.NoError(err) cluster := newTestRaftCluster(ctx, mockid.NewIDAllocator(), opt, storage.NewStorageWithMemoryBackend(), core.NewBasicCluster()) + cluster.coordinator = schedule.NewCoordinator(ctx, cluster, nil) regions := []*metapb.Region{ {Id: 1, StartKey: []byte(""), EndKey: []byte("a"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3})}, {Id: 2, StartKey: []byte("a"), EndKey: []byte("b"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3})}, @@ -111,5 +114,19 @@ func TestReportBatchSplit(t *testing.T) { {Id: 3, StartKey: []byte("c"), EndKey: []byte(""), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3})}, } _, err = cluster.HandleBatchReportSplit(&pdpb.ReportBatchSplitRequest{Regions: regions}) + re.Error(err) + + meta := &metapb.Region{Id: 1, StartKey: []byte(""), EndKey: []byte(""), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), + RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 1}} + region := core.NewRegionInfo(meta, meta.Peers[0]) + cluster.putRegion(region) + + regions = []*metapb.Region{ + {Id: 2, StartKey: []byte(""), EndKey: []byte("a"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 2}}, + {Id: 3, StartKey: []byte("a"), EndKey: []byte("b"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 2}}, + {Id: 4, StartKey: []byte("b"), EndKey: []byte("c"), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 2}}, + {Id: 1, StartKey: []byte("c"), EndKey: []byte(""), Peers: mockRegionPeer(cluster, []uint64{1, 2, 3}), RegionEpoch: &metapb.RegionEpoch{ConfVer: 1, Version: 2}}, + } + _, err = cluster.HandleBatchReportSplit(&pdpb.ReportBatchSplitRequest{Regions: regions}) re.NoError(err) } diff --git a/server/grpc_service.go b/server/grpc_service.go index 1a5441d363e..e006b64d1b1 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -1325,7 +1325,6 @@ retryLoop: select { case <-ctx.Done(): break retryLoop - case <-time.After(10 * time.Millisecond): } }