mirror of
https://github.com/kopia/kopia.git
synced 2026-01-23 13:58:08 -05:00
@@ -56,6 +56,11 @@ func internalRetry(ctx context.Context, desc string, attempt AttemptFunc, isRetr
|
||||
var lastError error
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
if cerr := ctx.Err(); cerr != nil {
|
||||
// nolint:wrapcheck
|
||||
return nil, cerr
|
||||
}
|
||||
|
||||
v, err := attempt()
|
||||
if err == nil {
|
||||
return v, nil
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package retry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/kopia/kopia/internal/testlogging"
|
||||
)
|
||||
@@ -58,3 +60,16 @@ func TestRetry(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryContextCancel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testlogging.Context(t)
|
||||
|
||||
canceledctx, cancel := context.WithCancel(ctx)
|
||||
cancel()
|
||||
|
||||
require.ErrorIs(t, context.Canceled, WithExponentialBackoffNoValue(canceledctx, "canceled", func() error {
|
||||
return errRetriable
|
||||
}, isRetriable))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user