Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Nov 17, 2024
1 parent b99701a commit 792b1b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/network/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type TierLimit struct {
// Tier limiter burst
Burst uint `json:"burst,omitempty" yaml:"burst,omitempty" validate:"gte=1" toml:"burst,omitempty"`
// Tier retries when getting transient errors, i.e. 429 or 500-599.
Retries int `json:"retries,omitempty" yaml:"retries,omitempty" toml:"retries,omitempty" validate:"gte=1"`
Retries int `json:"retries,omitempty" yaml:"retries,omitempty" toml:"retries,omitempty"`
}

// RequestLimit defines the limits on the requests that are sent to the API.
Expand Down
8 changes: 7 additions & 1 deletion internal/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func dAbs(d time.Duration) time.Duration {
return d
}

func Test_withRetry(t *testing.T) {
func TestWithRetry(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
Expand Down Expand Up @@ -166,6 +166,7 @@ func Test_withRetry(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
start := time.Now()
if err := WithRetry(tt.args.ctx, tt.args.l, tt.args.maxAttempts, tt.args.fn); (err != nil) != tt.wantErr {
t.Errorf("withRetry() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -179,6 +180,7 @@ func Test_withRetry(t *testing.T) {
})
}
t.Run("500 error handling", func(t *testing.T) {
t.Parallel()
waitFn = func(attempt int) time.Duration { return 50 * time.Millisecond }
defer func() {
waitFn = cubicWait
Expand Down Expand Up @@ -275,6 +277,7 @@ func Test_withRetry(t *testing.T) {
}

func Test_cubicWait(t *testing.T) {
t.Parallel()
type args struct {
attempt int
}
Expand All @@ -293,6 +296,7 @@ func Test_cubicWait(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := cubicWait(tt.args.attempt); !reflect.DeepEqual(got, tt.want) {
t.Errorf("waitTime() = %v, want %v", got, tt.want)
}
Expand All @@ -301,6 +305,7 @@ func Test_cubicWait(t *testing.T) {
}

func Test_isRecoverable(t *testing.T) {
t.Parallel()
type args struct {
statusCode int
}
Expand All @@ -323,6 +328,7 @@ func Test_isRecoverable(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := isRecoverable(tt.args.statusCode); got != tt.want {
t.Errorf("isRecoverable() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 792b1b3

Please sign in to comment.