Skip to content

Commit

Permalink
add unit test for get all
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <[email protected]>
  • Loading branch information
bufferflies committed Apr 7, 2023
1 parent d065501 commit add9492
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/movingaverage/avg_over_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestMinFilled(t *testing.T) {
for aotSize := 2; aotSize < 10; aotSize++ {
for mfSize := 2; mfSize < 10; mfSize++ {
tm := NewTimeMedian(aotSize, mfSize, interval)
re.Equal([]float64{}, tm.GetAll())
for i := 0; i < aotSize; i++ {
re.Equal(0.0, tm.Get())
tm.Add(rate*interval.Seconds(), interval)
Expand Down
3 changes: 3 additions & 0 deletions pkg/movingaverage/max_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (r *MaxFilter) Get() float64 {

// GetAll returns all the data points.
func (r *MaxFilter) GetAll() []float64 {
if r.count < r.size {
return r.records[:r.count]
}
return r.records
}

Expand Down
1 change: 1 addition & 0 deletions pkg/movingaverage/max_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestMaxFilter(t *testing.T) {

mf := NewMaxFilter(5)
re.Equal(empty, mf.Get())
re.Equal([]float64{}, mf.GetAll())

checkReset(re, mf, empty)
checkAdd(re, mf, data, expected)
Expand Down
3 changes: 3 additions & 0 deletions pkg/movingaverage/median_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (r *MedianFilter) Get() float64 {
}

func (r *MedianFilter) GetAll() []float64 {
if r.count < r.size {
return r.records[:r.count]
}
return r.records
}

Expand Down
1 change: 1 addition & 0 deletions pkg/movingaverage/moving_average_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestMedianFilter(t *testing.T) {

mf := NewMedianFilter(5)
re.Equal(empty, mf.Get())
re.Equal([]float64{}, mf.GetAll())

checkReset(re, mf, empty)
checkAdd(re, mf, data, expected)
Expand Down
3 changes: 3 additions & 0 deletions pkg/movingaverage/weight_moving_average.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (w *WMA) Get() float64 {

// GetAll returns all the data points.
func (w *WMA) GetAll() []float64 {
if w.count < w.size {
return w.records[:w.count]
}
return w.records
}

Expand Down
3 changes: 0 additions & 3 deletions pkg/schedule/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ func (h *hotScheduler) dispatch(typ statistics.RWType, cluster schedule.Cluster)
if h.conf.IsForbidRWType(typ) {
return nil
}

switch typ {
case statistics.Read:
return h.balanceHotReadRegions(cluster)
Expand Down Expand Up @@ -604,7 +603,6 @@ func (bs *balanceSolver) solve() []*operator.Operator {
if !bs.isValid() {
return nil
}

bs.cur = &solution{}
tryUpdateBestSolution := func() {
if label, ok := bs.filterUniformStore(); ok {
Expand Down Expand Up @@ -803,7 +801,6 @@ func (bs *balanceSolver) checkSrcByPriorityAndTolerance(minLoad, expectLoad *sta
}

func (bs *balanceSolver) checkSrcHistoryLoadByPriorityAndTolerance(current, expectLoad *statistics.StoreLoad, toleranceRatio float64) bool {
log.Info("check src history load", zap.Any("current", current), zap.Any("expect-load", expectLoad), zap.Any("bs", bs))
return bs.checkHistoryLoadsByPriority(current.HistoryLoads, func(i int) bool {
return slice.AllOf(current.HistoryLoads[i], func(j int) bool {
return current.HistoryLoads[i][j] > toleranceRatio*expectLoad.HistoryLoads[i][j]
Expand Down
2 changes: 2 additions & 0 deletions pkg/schedule/schedulers/hot_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,13 @@ func TestHotWriteRegionScheduleByteRateOnlyWithTiFlash(t *testing.T) {
tikvKeysSum += float64(storesBytes[i]/100) / 10
tikvQuerySum += float64(storesBytes[i]/100) / 10
}

for i := uint64(1); i <= storeCount; i++ {
if i != downStoreID {
tc.UpdateStorageWrittenBytes(i, storesBytes[i])
}
}

{ // Check the load expect
aliveTiKVCount := float64(aliveTiKVLastID - aliveTiKVStartID + 1)
allowLeaderTiKVCount := aliveTiKVCount - 1 // store 5 with evict leader
Expand Down
1 change: 0 additions & 1 deletion pkg/statistics/store_hot_peers_infos.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func summaryStoresLoadByEngine(
store := info.StoreInfo
id := store.GetID()
storeLoads, ok := storesLoads[id]
//storesHistoryLoads, ok1 := storesHistoryLoads[id]
if !ok || !collector.Filter(info, kind) {
continue
}
Expand Down

0 comments on commit add9492

Please sign in to comment.