Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test by increasing tolerance to process pauses #5400

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions component/common/loki/wal/timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@ import (
)

const (
delta = time.Millisecond * 20
maxOvershoot = 200 * time.Millisecond
)

func TestBackoffTimer(t *testing.T) {
var min = time.Millisecond * 300
var max = time.Second
timer := newBackoffTimer(min, max)

now := time.Now()
start := time.Now()
<-timer.C
require.WithinDuration(t, now.Add(min), time.Now(), delta, "expected backing off timer to fire in the minimum")
verifyElapsedTime(t, min, time.Since(start))

// backoff, and expect it will take twice the time
now = time.Now()
start = time.Now()
timer.backoff()
<-timer.C
require.WithinDuration(t, now.Add(min*2), time.Now(), delta, "expected backing off timer to fire in the twice the minimum")
verifyElapsedTime(t, 2*min, time.Since(start))

// backoff capped, backoff will actually be 1200ms, but capped at 1000
now = time.Now()
start = time.Now()
timer.backoff()
<-timer.C
require.WithinDuration(t, now.Add(max), time.Now(), delta, "expected backing off timer to fire in the max")
verifyElapsedTime(t, max, time.Since(start))
}

func verifyElapsedTime(t *testing.T, expected time.Duration, elapsed time.Duration) {
require.GreaterOrEqual(t, elapsed, expected, "elapsed time should be greater or equal to the expected value")
require.Less(t, elapsed, expected+maxOvershoot, "elapsed time should be less than the expected value plus the max overshoot")
}