github.com/aaabigfish/gopkg@v1.1.0/stat/counter/rolling_test.go (about) 1 package counter 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestRollingCounterMinInterval(t *testing.T) { 9 count := NewRolling(time.Second/2, 10) 10 tk1 := time.NewTicker(5 * time.Millisecond) 11 defer tk1.Stop() 12 for i := 0; i < 100; i++ { 13 <-tk1.C 14 count.Add(1) 15 } 16 17 v := count.Value() 18 t.Logf("count value: %d", v) 19 // 10% of error when bucket is 10 20 if v < 90 || v > 110 { 21 t.Errorf("expect value in [90-110] get %d", v) 22 } 23 }