chore: reorg imports, format code, make MaxRetires default to 0 (#1165)
* chore: reverse the order of stopping services * chore: reverse the order of stopping services * chore: reorg imports, format code * chore: format code, and refactor * feat: change MaxRetries default to 0, disable retry
This commit is contained in:
@@ -2,17 +2,20 @@ package serverinterceptors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tal-tech/go-zero/core/retry"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRetryInterceptor(t *testing.T) {
|
||||
t.Run("retries exceeded", func(t *testing.T) {
|
||||
interceptor := RetryInterceptor(2)
|
||||
ctx := metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{retry.AttemptMetadataKey: "3"}))
|
||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
ctx := metadata.NewIncomingContext(context.Background(),
|
||||
metadata.New(map[string]string{retry.AttemptMetadataKey: "3"}))
|
||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context,
|
||||
req interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
})
|
||||
assert.Error(t, err)
|
||||
@@ -21,8 +24,10 @@ func TestRetryInterceptor(t *testing.T) {
|
||||
|
||||
t.Run("reasonable retries", func(t *testing.T) {
|
||||
interceptor := RetryInterceptor(2)
|
||||
ctx := metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{retry.AttemptMetadataKey: "2"}))
|
||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
ctx := metadata.NewIncomingContext(context.Background(),
|
||||
metadata.New(map[string]string{retry.AttemptMetadataKey: "2"}))
|
||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context,
|
||||
req interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
@@ -30,11 +35,11 @@ func TestRetryInterceptor(t *testing.T) {
|
||||
})
|
||||
t.Run("no retries", func(t *testing.T) {
|
||||
interceptor := RetryInterceptor(0)
|
||||
resp, err := interceptor(context.Background(), nil, nil, func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
})
|
||||
resp, err := interceptor(context.Background(), nil, nil,
|
||||
func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return nil, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, resp)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user