@@ -608,7 +608,7 @@ func TestRegionHasLearner(t *testing.T) {
608608 checkLeader (scatterer .ordinaryEngine .selectedLeader )
609609}
610610
611- // TestSelectedStores tests if the peer count has changed due to the picking strategy.
611+ // TestSelectedStoresTooFewPeers tests if the peer count has changed due to the picking strategy.
612612// Ref https://github.com/tikv/pd/issues/4565
613613func (s * testScatterRegionSuite ) TestSelectedStores (c * C ) {
614614 ctx , cancel := context .WithCancel (context .Background ())
@@ -644,6 +644,43 @@ func (s *testScatterRegionSuite) TestSelectedStores(c *C) {
644644 }
645645}
646646
647+ // TestSelectedStoresTooManyPeers tests if the peer count has changed due to the picking strategy.
648+ // Ref https://github.com/tikv/pd/issues/5909
649+ func TestSelectedStoresTooManyPeers (t * testing.T ) {
650+ re := require .New (t )
651+ ctx , cancel := context .WithCancel (context .Background ())
652+ defer cancel ()
653+ opt := config .NewTestOptions ()
654+ tc := mockcluster .NewCluster (ctx , opt )
655+ stream := hbstream .NewTestHeartbeatStreams (ctx , tc .ID , tc , false )
656+ oc := NewOperatorController (ctx , tc , stream )
657+ // Add 4 stores.
658+ for i := uint64 (1 ); i <= 5 ; i ++ {
659+ tc .AddRegionStore (i , 0 )
660+ // prevent store from being disconnected
661+ tc .SetStoreLastHeartbeatInterval (i , - 10 * time .Minute )
662+ }
663+ group := "group"
664+ scatterer := NewRegionScatterer (ctx , tc , oc )
665+ // priority 4 > 1 > 5 > 2 == 3
666+ for i := 0 ; i < 1200 ; i ++ {
667+ scatterer .ordinaryEngine .selectedPeer .Put (2 , group )
668+ scatterer .ordinaryEngine .selectedPeer .Put (3 , group )
669+ }
670+ for i := 0 ; i < 800 ; i ++ {
671+ scatterer .ordinaryEngine .selectedPeer .Put (5 , group )
672+ }
673+ for i := 0 ; i < 400 ; i ++ {
674+ scatterer .ordinaryEngine .selectedPeer .Put (1 , group )
675+ }
676+ // test region with peer 1 2 3
677+ for i := uint64 (1 ); i < 20 ; i ++ {
678+ region := tc .AddLeaderRegion (i + 200 , i % 3 + 1 , (i + 1 )% 3 + 1 , (i + 2 )% 3 + 1 )
679+ op := scatterer .scatterRegion (region , group )
680+ re .False (isPeerCountChanged (op ))
681+ }
682+ }
683+
647684// TestBalanceRegion tests whether region peers and leaders are balanced after scatter.
648685// ref https://github.com/tikv/pd/issues/6017
649686func TestBalanceRegion (t * testing.T ) {
0 commit comments