diff --git a/server/coordinator_test.go b/server/coordinator_test.go index 5fc8e6778b13..b9c95c9d9586 100644 --- a/server/coordinator_test.go +++ b/server/coordinator_test.go @@ -15,6 +15,7 @@ package server import ( "fmt" + "math/rand" "time" . "github.com/pingcap/check" @@ -236,6 +237,29 @@ func dispatchHeartbeat(c *C, co *coordinator, region *core.RegionInfo, stream *m co.dispatch(region) } +func (s *testCoordinatorSuite) TestCollectMetrics(c *C) { + _, opt := newTestScheduleConfig() + tc := newTestClusterInfo(opt) + hbStreams := newHeartbeatStreams(tc.getClusterID()) + defer hbStreams.Close() + + co := newCoordinator(tc.clusterInfo, hbStreams, namespace.DefaultClassifier) + co.run() + + for i := 0; i <= 10; i++ { + go func(i int) { + for j := 0; j < 10000; j++ { + tc.addRegionStore(uint64(i%5), rand.Intn(200)) + } + }(i) + } + for i := 0; i < 1000; i++ { + co.collectHotSpotMetrics() + co.collectSchedulerMetrics() + co.cluster.collectMetrics() + } +} + func (s *testCoordinatorSuite) TestCheckRegion(c *C) { cfg, opt := newTestScheduleConfig() cfg.DisableLearner = false