rolling_test.go 422 B

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