Skip to content

Commit

Permalink
fix flakey ticker test (influxdata#7997)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka authored and pmalek-sumo committed Aug 19, 2020
1 parent a868a96 commit 88a3d04
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions agent/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAlignedTickerJitter(t *testing.T) {

clock := clock.NewMock()
since := clock.Now()
until := since.Add(60 * time.Second)
until := since.Add(61 * time.Second)

ticker := newAlignedTicker(since, interval, jitter, clock)
defer ticker.Stop()
Expand All @@ -61,12 +61,14 @@ func TestAlignedTickerJitter(t *testing.T) {
for !clock.Now().After(until) {
select {
case tm := <-ticker.Elapsed():
require.True(t, tm.Sub(last) <= 15*time.Second)
require.True(t, tm.Sub(last) >= 5*time.Second)
dur := tm.Sub(last)
// 10s interval + 5s jitter + up to 1s late firing.
require.True(t, dur <= 16*time.Second, "expected elapsed time to be less than 16 seconds, but was %s", dur)
require.True(t, dur >= 5*time.Second, "expected elapsed time to be more than 5 seconds, but was %s", dur)
last = last.Add(interval)
default:
}
clock.Add(5 * time.Second)
clock.Add(1 * time.Second)
}
}

Expand Down

0 comments on commit 88a3d04

Please sign in to comment.