github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/ldbutils/count_meter_test.go (about) 1 package ldbutils 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestCountMeter(t *testing.T) { 10 m := NewCountMeter() 11 // Shutdown the meter so we manually control its ticks. 12 m.Shutdown() 13 14 var count1 float64 15 var count5 float64 16 var count15 float64 17 var countMean float64 18 19 for i := 0; i < 100; i++ { 20 count1 = 0 21 if i > 4 { 22 count5 -= float64(((i - 5) * 4) + 10) 23 } 24 if i > 14 { 25 count15 -= float64(((i - 15) * 4) + 10) 26 } 27 f := float64((i * 4) + 10) 28 count1 += f 29 count5 += f 30 count15 += f 31 countMean += f 32 for j := 1; j < 5; j++ { 33 m.Mark(int64(i + j)) 34 } 35 s := m.Snapshot() 36 require.Equal(t, count1, m.Rate1(), "Invalid Rate1 for i=%d", i) 37 require.Equal(t, count5, m.Rate5(), "Invalid Rate5 for i=%d", i) 38 require.Equal(t, count15, m.Rate15(), "Invalid Rate15 for i=%d", i) 39 require.Equal(t, countMean, m.RateMean(), "Invalid RateMean for i=%d", i) 40 require.Equal(t, int64(countMean), m.Count(), "Invalid Count for i=%d", i) 41 require.Equal(t, s.Rate1(), m.Rate1()) 42 require.Equal(t, s.Rate5(), m.Rate5()) 43 require.Equal(t, s.Rate15(), m.Rate15()) 44 require.Equal(t, s.RateMean(), m.RateMean()) 45 require.Equal(t, s.Count(), m.Count()) 46 m.tick() 47 } 48 }