@@ -67,6 +67,7 @@ func TestScatterRegions(t *testing.T) {
6767 scatter (re , 5 , 50 , true )
6868 scatter (re , 5 , 500 , true )
6969 scatter (re , 6 , 50 , true )
70+ scatter (re , 7 , 71 , true )
7071 scatter (re , 5 , 50 , false )
7172 scatterSpecial (re , 3 , 6 , 50 )
7273 scatterSpecial (re , 5 , 5 , 50 )
@@ -132,20 +133,36 @@ func scatter(re *require.Assertions, numStores, numRegions uint64, useRules bool
132133 }
133134 }
134135 }
136+ maxStorePeerTotalCount := uint64 (0 )
137+ minStorePeerTotalCount := uint64 (math .MaxUint64 )
135138
136139 // Each store should have the same number of peers.
137140 for _ , count := range countPeers {
138- re .LessOrEqual (float64 (count ), 1.1 * float64 (numRegions * 3 )/ float64 (numStores ))
139- re .GreaterOrEqual (float64 (count ), 0.9 * float64 (numRegions * 3 )/ float64 (numStores ))
141+ if count > maxStorePeerTotalCount {
142+ maxStorePeerTotalCount = count
143+ }
144+ if count < minStorePeerTotalCount {
145+ minStorePeerTotalCount = count
146+ }
140147 }
148+ re .LessOrEqual (maxStorePeerTotalCount - minStorePeerTotalCount , uint64 (1 ))
141149
142150 // Each store should have the same number of leaders.
143151 re .Len (countPeers , int (numStores ))
144152 re .Len (countLeader , int (numStores ))
153+
154+ maxStoreLeaderTotalCount := uint64 (0 )
155+ minStoreLeaderTotalCount := uint64 (math .MaxUint64 )
145156 for _ , count := range countLeader {
146- re .LessOrEqual (float64 (count ), 1.1 * float64 (numRegions )/ float64 (numStores ))
147- re .GreaterOrEqual (float64 (count ), 0.9 * float64 (numRegions )/ float64 (numStores ))
157+ if count > maxStoreLeaderTotalCount {
158+ maxStoreLeaderTotalCount = count
159+ }
160+ if count < minStoreLeaderTotalCount {
161+ minStoreLeaderTotalCount = count
162+ }
148163 }
164+ // Since the scatter leader depends on the scatter result of the peer, the maximum difference is 2.
165+ re .LessOrEqual (maxStoreLeaderTotalCount - minStoreLeaderTotalCount , uint64 (2 ))
149166 re .GreaterOrEqual (noNeedMoveNum , 0 )
150167}
151168
0 commit comments