Skip to content

tp: relax strict upper bound check in TestBackoffBeforeDeadline - #48

Open
Aditya-9-6 wants to merge 1 commit into
superfly:mainfrom
Aditya-9-6:fix/flaky-deadline-backoff-test
Open

Aditya-9-6 wants to merge 1 commit into
superfly:mainfrom
Aditya-9-6:fix/flaky-deadline-backoff-test

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Problem

In tp/client_test.go, TestBackoffBeforeDeadline/backoff_sleeps_past_deadline creates a context with a 10-second timeout:

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

bo := boBeforeDeadline(ctx, time.Hour)
assert.True(t, bo > 8*time.Second, "got %s", bo)
assert.True(t, bo < 9*time.Second, "got %s", bo)

boBeforeDeadline computes:

remaining := time.Until(deadline) // ~10s
slack := remaining / 2
if slack > pollDeadlineSlack { // pollDeadlineSlack = 1s
    slack = pollDeadlineSlack
}
latest := remaining - slack // 10s - 1s = 9s

When the test executes rapidly and negligible time has elapsed between context creation and time.Until(deadline), remaining is 10s and latest evaluates to exactly 9s.
Because the assertion checks strict inequality (bo < 9*time.Second), it intermittently fails with:

client_test.go:42: got 9s

Solution

Change the upper bound assertion to assert.True(t, bo <= 9*time.Second, "got %s", bo). This permits the boundary value of 10s - 1s = 9s when time.Until(deadline) has not yet ticked below 10s, while preserving the test invariant that bo is clamped to roughly remaining - pollDeadlineSlack.

When execution is fast, remaining time minus pollDeadlineSlack can be exactly 9s, causing �o < 9*time.Second to fail with got 9s. Using <= avoids the flaky boundary failure while preserving the test invariant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant