Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry should be limited by the max backoff if no maximum number of tr…
…ies is specified (#2102) * fix retry bug, use default retry for invocation db update * add tests, implement floor for max retries * table-based tests
- Loading branch information
Showing
4 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "retry", | ||
srcs = ["retry.go"], | ||
importpath = "github.com/buildbuddy-io/buildbuddy/server/util/retry", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_test( | ||
name = "retry_test", | ||
srcs = ["retry_test.go"], | ||
deps = [ | ||
":retry", | ||
"@com_github_stretchr_testify//assert", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package retry_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/buildbuddy-io/buildbuddy/server/util/retry" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMaxRetryFromBackoff(t *testing.T) { | ||
tests := map[string]struct { | ||
inputOptions *retry.Options | ||
expectedMaxAttempts int | ||
}{ | ||
"exact backoff boundary": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 24, | ||
Multiplier: 2, | ||
MaxRetries: 0, | ||
}, | ||
expectedMaxAttempts: 4, | ||
}, | ||
"above exact backoff boundary": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 25, | ||
Multiplier: 2, | ||
MaxRetries: 0, | ||
}, | ||
expectedMaxAttempts: 5, | ||
}, | ||
"below exact backoff boundary": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 23, | ||
Multiplier: 2, | ||
MaxRetries: 0, | ||
}, | ||
expectedMaxAttempts: 4, | ||
}, | ||
"manually set maximum above calculated backoff": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 23, | ||
Multiplier: 2, | ||
MaxRetries: 7, | ||
}, | ||
expectedMaxAttempts: 7, | ||
}, | ||
"manually set maximum below calculated backoff": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 23, | ||
Multiplier: 2, | ||
MaxRetries: 2, | ||
}, | ||
expectedMaxAttempts: 2, | ||
}, | ||
"initial backoff greater than maximum": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 1, | ||
Multiplier: 2, | ||
MaxRetries: 0, | ||
}, | ||
expectedMaxAttempts: 1, | ||
}, | ||
"multiplier less than or equal to one": { | ||
inputOptions: &retry.Options{ | ||
InitialBackoff: 3, | ||
MaxBackoff: 7, | ||
Multiplier: 0.5, | ||
MaxRetries: 0, | ||
}, | ||
expectedMaxAttempts: 1, | ||
}, | ||
} | ||
for name, tc := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
assert.Equal(t, tc.expectedMaxAttempts, retry.New(context.Background(), tc.inputOptions).MaxAttempts()) | ||
}) | ||
} | ||
} |