Move retry logic to errors.IsRetrialbeError
Also added unit tests.
This commit is contained in:
parent
a0c38a4f00
commit
5d542d398f
@ -2,6 +2,7 @@ package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -134,6 +135,9 @@ func IsRetriableError(err error) bool {
|
||||
}); ok {
|
||||
return e.RetriableError()
|
||||
}
|
||||
if cause, ok := Cause(err).(*url.Error); ok {
|
||||
return cause.Temporary() || cause.Timeout()
|
||||
}
|
||||
if parent := parentOf(err); parent != nil {
|
||||
return IsRetriableError(parent)
|
||||
}
|
||||
|
46
errors/types_test.go
Normal file
46
errors/types_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package errors_test
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/git-lfs/git-lfs/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type TemporaryError struct {
|
||||
}
|
||||
|
||||
func (e TemporaryError) Error() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (e TemporaryError) Temporary() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type TimeoutError struct {
|
||||
}
|
||||
|
||||
func (e TimeoutError) Error() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (e TimeoutError) Timeout() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func TestCanRetryOnTemporaryError(t *testing.T) {
|
||||
err := &url.Error{Err: TemporaryError{}}
|
||||
assert.True(t, errors.IsRetriableError(err))
|
||||
}
|
||||
|
||||
func TestCanRetryOnTimeoutError(t *testing.T) {
|
||||
err := &url.Error{Err: TimeoutError{}}
|
||||
assert.True(t, errors.IsRetriableError(err))
|
||||
}
|
||||
|
||||
func TestCannotRetryOnGenericUrlError(t *testing.T) {
|
||||
err := &url.Error{Err: errors.New("")}
|
||||
assert.False(t, errors.IsRetriableError(err))
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package tq
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
@ -634,12 +633,7 @@ func (q *TransferQueue) run() {
|
||||
|
||||
// canRetry returns whether or not the given error "err" is retriable.
|
||||
func (q *TransferQueue) canRetry(err error) bool {
|
||||
switch cause := errors.Cause(err).(type) {
|
||||
case *url.Error:
|
||||
return cause.Temporary() || cause.Timeout()
|
||||
default:
|
||||
return errors.IsRetriableError(err)
|
||||
}
|
||||
return errors.IsRetriableError(err)
|
||||
}
|
||||
|
||||
// canRetryObject returns whether the given error is retriable for the object
|
||||
|
Loading…
Reference in New Issue
Block a user