Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: HunDunDM <hundundm@gmail.com>
  • Loading branch information
HunDunDM committed Mar 11, 2021
1 parent 84427a3 commit 5ea19b8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/statistics/region_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,15 @@ func (t *testRegionStatisticsSuite) TestRegionLabelIsolationLevel(c *C) {
{"rack": "r2", "host": "h2"},
{"rack": "r3", "host": "h3"},
},
{
// isolated by host
{"zone": "z1", "rack": "r1", "host": "h1"},
{"zone": "z1", "rack": "r2", "host": "h2"},
{"zone": "z1", "host": "h3"},
},
}
res := []string{"rack", "host", "zone", "rack", "none", "rack"}
counter := map[string]int{"none": 1, "host": 1, "rack": 3, "zone": 1}
res := []string{"rack", "host", "zone", "rack", "none", "rack", "host"}
counter := map[string]int{"none": 1, "host": 2, "rack": 3, "zone": 1}
regionID := 1
f := func(labels []map[string]string, res string, locationLabels []string) {
metaStores := []*metapb.Store{
Expand Down Expand Up @@ -261,10 +267,13 @@ func (t *testRegionStatisticsSuite) TestRegionLabelIsolationLevel(c *C) {
c.Assert(label, Equals, nonIsolation)
label = getRegionLabelIsolation(nil, nil)
c.Assert(label, Equals, nonIsolation)
store := core.NewStoreInfo(&metapb.Store{Id: 1, Address: "mock://tikv-1"}, core.SetStoreLabels([]*metapb.StoreLabel{{Key: "foo", Value: "bar"}}))
label = getRegionLabelIsolation([]*core.StoreInfo{store}, locationLabels)
c.Assert(label, Equals, "zone")

regionID = 1
res = []string{"rack", "none", "zone", "rack", "none", "rack"}
counter = map[string]int{"none": 2, "host": 0, "rack": 3, "zone": 1}
res = []string{"rack", "none", "zone", "rack", "none", "rack", "none"}
counter = map[string]int{"none": 3, "host": 0, "rack": 3, "zone": 1}
locationLabels = []string{"zone", "rack"}

for i, labels := range labelsSet {
Expand Down

0 comments on commit 5ea19b8

Please sign in to comment.