Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for IsServiceTransientError #5551

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,49 @@ import (
"github.com/uber/cadence/common/types"
)

func TestIsServiceTransientError_ContextTimeout(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
time.Sleep(100 * time.Millisecond)

require.False(t, IsServiceTransientError(ctx.Err()))
}

func TestIsServiceTransientError_YARPCDeadlineExceeded(t *testing.T) {
yarpcErr := yarpcerrors.DeadlineExceededErrorf("yarpc deadline exceeded")
require.False(t, IsServiceTransientError(yarpcErr))
}
func TestIsServiceTransientError(t *testing.T) {
for name, c := range map[string]struct {
err error
want bool
}{
"ContextTimeout": {
err: context.DeadlineExceeded,
want: false,
},
"YARPCDeadlineExceeded": {
err: yarpcerrors.DeadlineExceededErrorf("yarpc deadline exceeded"),
want: false,
},
"YARPCUnavailable": {
err: yarpcerrors.UnavailableErrorf("yarpc unavailable"),
arzonus marked this conversation as resolved.
Show resolved Hide resolved
want: true,
},
"YARPCUnknown": {
err: yarpcerrors.UnknownErrorf("yarpc unknown"),
want: true,
},
"YARPCInternal": {
err: yarpcerrors.InternalErrorf("yarpc internal"),
want: true,
},
"ContextCancel": {
err: context.Canceled,
want: false,
},
"ServiceBusyError": {
err: &types.ServiceBusyError{},
want: true,
},
"ShardOwnershipLostError": {
err: &types.ShardOwnershipLostError{},
want: true,
},
} {
t.Run(name, func(t *testing.T) {
require.Equal(t, c.want, IsServiceTransientError(c.err))
})
}

func TestIsServiceTransientError_ContextCancel(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
require.False(t, IsServiceTransientError(ctx.Err()))
}

func TestIsContextTimeoutError(t *testing.T) {
Expand Down