github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/telemetry/ticker_test.go (about) 1 package telemetry 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestWithJitter(t *testing.T) { 11 testCases := []struct { 12 d time.Duration 13 minExp time.Duration 14 maxExp time.Duration 15 }{ 16 { 17 d: 1 * time.Minute, 18 minExp: 1 * time.Minute, 19 maxExp: 1*time.Minute + jitterUpperBound*time.Second, 20 }, 21 { 22 d: 5 * time.Minute, 23 minExp: 5 * time.Minute, 24 maxExp: 5*time.Minute + jitterUpperBound*time.Second, 25 }, 26 { 27 d: 60 * time.Second, 28 minExp: 60 * time.Second, 29 maxExp: 60*time.Second + jitterUpperBound*time.Second, 30 }, 31 { 32 d: 5 * time.Second, 33 minExp: 5 * time.Second, 34 maxExp: 5*time.Second + jitterUpperBound*time.Second, 35 }, 36 { 37 d: 0 * time.Second, 38 minExp: 0 * time.Second, 39 maxExp: 0*time.Second + jitterUpperBound*time.Second, 40 }, 41 } 42 43 for _, tc := range testCases { 44 require.GreaterOrEqual(t, withJitter(tc.d), tc.minExp) 45 require.Less(t, withJitter(tc.d), tc.maxExp) 46 } 47 }