throttler: Fix the aggregated average historic value if multiple threads are used. (#1985)

This commit is contained in:
Michael Berlin 2016-08-24 10:51:16 -07:00 коммит произвёл GitHub
Родитель a983b1aa7d
Коммит 8d6d92bac5
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -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)
}
}