mirror of
https://github.com/restic/restic.git
synced 2025-08-26 12:47:42 +00:00
backend/retry: do not log final error if context was canceled
Calls to `List(ctx, ...)` are usually stopped by canceling the context once no further entries are required by the caller. Thus, don't log the final error if the used context was canceled.
This commit is contained in:
@@ -460,7 +460,7 @@ func TestNotifyWithSuccessIsNotCalled(t *testing.T) {
|
||||
t.Fatal("Success should not have been called")
|
||||
}
|
||||
|
||||
err := retryNotifyErrorWithSuccess(operation, &backoff.ZeroBackOff{}, notify, success)
|
||||
err := retryNotifyErrorWithSuccess(operation, backoff.WithContext(&backoff.ZeroBackOff{}, context.Background()), notify, success)
|
||||
if err != nil {
|
||||
t.Fatal("retry should not have returned an error")
|
||||
}
|
||||
@@ -486,7 +486,7 @@ func TestNotifyWithSuccessIsCalled(t *testing.T) {
|
||||
successCalled++
|
||||
}
|
||||
|
||||
err := retryNotifyErrorWithSuccess(operation, &backoff.ZeroBackOff{}, notify, success)
|
||||
err := retryNotifyErrorWithSuccess(operation, backoff.WithContext(&backoff.ZeroBackOff{}, context.Background()), notify, success)
|
||||
if err != nil {
|
||||
t.Fatal("retry should not have returned an error")
|
||||
}
|
||||
@@ -515,12 +515,31 @@ func TestNotifyWithSuccessFinalError(t *testing.T) {
|
||||
successCalled++
|
||||
}
|
||||
|
||||
err := retryNotifyErrorWithSuccess(operation, backoff.WithMaxRetries(&backoff.ZeroBackOff{}, 5), notify, success)
|
||||
err := retryNotifyErrorWithSuccess(operation, backoff.WithContext(backoff.WithMaxRetries(&backoff.ZeroBackOff{}, 5), context.Background()), notify, success)
|
||||
test.Assert(t, err.Error() == "expected error in test", "wrong error message %v", err)
|
||||
test.Equals(t, 6, notifyCalled, "notify should have been called 6 times")
|
||||
test.Equals(t, 0, successCalled, "success should not have been called")
|
||||
}
|
||||
|
||||
func TestNotifyWithCancelError(t *testing.T) {
|
||||
operation := func() error {
|
||||
return errors.New("expected error in test")
|
||||
}
|
||||
|
||||
notify := func(error, time.Duration) {
|
||||
t.Error("unexpected call to notify")
|
||||
}
|
||||
|
||||
success := func(retries int) {
|
||||
t.Error("unexpected call to success")
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
|
||||
err := retryNotifyErrorWithSuccess(operation, backoff.WithContext(&backoff.ZeroBackOff{}, ctx), notify, success)
|
||||
test.Assert(t, err == context.Canceled, "wrong error message %v", err)
|
||||
}
|
||||
|
||||
type testClock struct {
|
||||
Time time.Time
|
||||
}
|
||||
|
Reference in New Issue
Block a user