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

Exponential backoff and longer wait threshold to de-flake test #126

Merged
merged 1 commit into from
Jan 28, 2025
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: 14 additions & 5 deletions reflect_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ func getFileDescriptorSet(
) (*connect.Response[reflectv1beta1.GetFileDescriptorSetResponse], error) {
// We are hitting the real buf.build endpoint. To work-around spurious errors
// from a temporary network partition or encountering the endpoint rate limit,
// we will retry up to 3 times, with delay in between.
// we will retry for up to a minute. (The long retry window is to allow
// exponential back-off delays between attempts and to be resilient to cases
// in CI where multiple concurrent jobs are hitting the endpoint and exceeding
// the rate limit.)
var lastErr error
for i := 0; i < 3; i++ {
if i > 0 {
delay := 250 * time.Millisecond
start := time.Now()
for {
if lastErr != nil {
// delay between attempts
time.Sleep(time.Second)
time.Sleep(delay)
delay *= 2
}
resp, err := client.GetFileDescriptorSet(ctx, req)
if err == nil {
Expand All @@ -102,11 +108,14 @@ func getFileDescriptorSet(
if code != connect.CodeUnavailable && code != connect.CodeResourceExhausted {
return nil, err
}
if time.Since(start) > time.Minute {
// Took too long. Fail.
return nil, err
}
// On "unavailable" (could be transient network issue) or
// "resource exhausted" (rate limited), we loop and try again.
lastErr = err
}
return nil, lastErr
}

// Message types in buf.build/googleapis/googleapis. Generated via the following:
Expand Down
Loading