mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-18 12:24:32 -05:00
c743398a23
Generalize retrier: * Generalize Do to use a supplied 'retriable' function * Make clock an optional argument in NewIntervalRetrier * Move grpc/retrier to interal package * Update existing unittests to not use retry feature Add retryDownloadToTempDir: * Wrap downloadToTempDir with retrier. * Retry if TCP connection is reset. * Abort by canceling the context. * Use a mock server in the unit test that serves responses depending on the state received through a state channel. Co-authored-by: katexochen <49727155+katexochen@users.noreply.github.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package retry
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func TestServiceIsUnavailable(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
err error
|
|
wantUnavailable bool
|
|
}{
|
|
"nil": {},
|
|
"not status error": {
|
|
err: errors.New("error"),
|
|
},
|
|
"not unavailable": {
|
|
err: status.Error(codes.Internal, "error"),
|
|
},
|
|
"unavailable error with authentication handshake failure": {
|
|
err: status.Error(codes.Unavailable, `connection error: desc = "transport: authentication handshake failed`),
|
|
},
|
|
"normal unavailable error": {
|
|
err: status.Error(codes.Unavailable, "error"),
|
|
wantUnavailable: true,
|
|
},
|
|
"wrapped error": {
|
|
err: fmt.Errorf("some wrapping: %w", status.Error(codes.Unavailable, "error")),
|
|
wantUnavailable: true,
|
|
},
|
|
"code unknown": {
|
|
err: status.Error(codes.Unknown, "unknown"),
|
|
},
|
|
}
|
|
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
assert.Equal(tc.wantUnavailable, ServiceIsUnavailable(tc.err))
|
|
})
|
|
}
|
|
}
|