зеркало из https://github.com/github/vitess-gh.git
throttler: Fix the aggregated average historic value if multiple threads are used. (#1985)
This commit is contained in:
Родитель
a983b1aa7d
Коммит
8d6d92bac5
|
@ -35,5 +35,5 @@ func (h *aggregatedIntervalHistory) average(from, to time.Time) float64 {
|
|||
for i := 0; i < h.threadCount; i++ {
|
||||
sum += h.historyPerThread[i].average(from, to)
|
||||
}
|
||||
return sum / float64(h.threadCount)
|
||||
return sum
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package throttler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAggregatedIntervalHistory(t *testing.T) {
|
||||
h := newAggregatedIntervalHistory(10, 1*time.Second, 2)
|
||||
h.addPerThread(0, record{sinceZero(0 * time.Second), 1000})
|
||||
h.addPerThread(1, record{sinceZero(0 * time.Second), 2000})
|
||||
|
||||
if got, want := h.average(sinceZero(250*time.Millisecond), sinceZero(750*time.Millisecond)), 3000.0; got != want {
|
||||
t.Errorf("average(0.25s, 0.75s) across both threads = %v, want = %v", got, want)
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче