Denis Kirillov
5d6d5e41d0
Some checks failed
/ DCO (pull_request) Successful in 1m40s
/ Builds (1.20) (pull_request) Successful in 2m22s
/ Builds (1.21) (pull_request) Successful in 1m56s
/ Vulncheck (pull_request) Failing after 2m40s
/ Lint (pull_request) Successful in 4m31s
/ Tests (1.20) (pull_request) Successful in 2m45s
/ Tests (1.21) (pull_request) Successful in 2m38s
Add two strategy for PutBucketSettings request retryer:
* exponential backoff (increasing up to `max_backoff` delays with jitter)
* constant backoff (always the same `max_backoff` delay between requests)
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
(cherry picked from commit bb81afc14a
)
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package retryer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/tree"
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRetryer(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
retryer := retry.NewStandard(func(options *retry.StandardOptions) {
|
|
options.MaxAttempts = 3
|
|
options.Backoff = retry.BackoffDelayerFunc(func(int, error) (time.Duration, error) { return 0, nil })
|
|
options.Retryables = []retry.IsErrorRetryable{retry.IsErrorRetryableFunc(func(err error) aws.Ternary {
|
|
if errors.Is(err, tree.ErrNodeAccessDenied) {
|
|
return aws.TrueTernary
|
|
}
|
|
return aws.FalseTernary
|
|
})}
|
|
})
|
|
|
|
t.Run("no retryable", func(t *testing.T) {
|
|
count := 0
|
|
err := MakeWithRetry(ctx, func() error {
|
|
count++
|
|
if count == 1 {
|
|
return tree.ErrNodeNotFound
|
|
}
|
|
return tree.ErrNodeAccessDenied
|
|
}, retryer)
|
|
require.ErrorIs(t, err, tree.ErrNodeNotFound)
|
|
})
|
|
|
|
t.Run("retry", func(t *testing.T) {
|
|
count := 0
|
|
err := MakeWithRetry(ctx, func() error {
|
|
count++
|
|
if count < 3 {
|
|
return tree.ErrNodeAccessDenied
|
|
}
|
|
return nil
|
|
}, retryer)
|
|
require.NoError(t, err)
|
|
})
|
|
|
|
t.Run("retry exhausted", func(t *testing.T) {
|
|
err := MakeWithRetry(ctx, func() error {
|
|
return tree.ErrNodeAccessDenied
|
|
}, retryer)
|
|
require.ErrorIs(t, err, tree.ErrNodeAccessDenied)
|
|
})
|
|
}
|