|
|
@ -603,14 +603,16 @@ func TestSortRegions(t *testing.T) {
|
|
|
|
report.RegionLatency[3] = time.Second * time.Duration(6)
|
|
|
|
report.RegionLatency[3] = time.Second * time.Duration(6)
|
|
|
|
report.RegionLatency[4] = time.Second * time.Duration(0)
|
|
|
|
report.RegionLatency[4] = time.Second * time.Duration(0)
|
|
|
|
report.RegionLatency[5] = time.Second * time.Duration(2)
|
|
|
|
report.RegionLatency[5] = time.Second * time.Duration(2)
|
|
|
|
got := sortRegions(unsortedMap, report)
|
|
|
|
sortedMap := sortRegions(unsortedMap, report)
|
|
|
|
|
|
|
|
|
|
|
|
// Sorting by latency this should result in rid: 5, 2, 1, 3
|
|
|
|
// Sorting by latency this should result in rid: 5, 2, 1, 3
|
|
|
|
// rid 4 with latency 0 should be at the end
|
|
|
|
// rid 4 with latency 0 should be at the end
|
|
|
|
expected := []int{5, 2, 1, 3, 4}
|
|
|
|
want := []int{5, 2, 1, 3, 4}
|
|
|
|
for idx, want := range expected {
|
|
|
|
got := make([]int, len(sortedMap))
|
|
|
|
if got[idx].RegionID != want {
|
|
|
|
for i, r := range sortedMap {
|
|
|
|
t.Errorf("idx:%v got:%v want:%v\n", idx, got[idx].RegionID, want)
|
|
|
|
got[i] = r.RegionID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(got, want) {
|
|
|
|
|
|
|
|
t.Errorf("got %v; want %v", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|