retryinterceptor_test.go 720 B

123456789101112131415161718192021222324252627
  1. package clientinterceptors
  2. import (
  3. "context"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tal-tech/go-zero/core/retry"
  6. "google.golang.org/grpc"
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/status"
  9. "testing"
  10. )
  11. func TestRetryInterceptor_WithMax(t *testing.T) {
  12. n := 4
  13. for i := 0; i < n; i++ {
  14. count := 0
  15. cc := new(grpc.ClientConn)
  16. err := RetryInterceptor(true)(context.Background(), "/1", nil, nil, cc,
  17. func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, opts ...grpc.CallOption) error {
  18. count++
  19. return status.Error(codes.ResourceExhausted, "ResourceExhausted")
  20. }, retry.WithMax(i))
  21. assert.Error(t, err)
  22. assert.Equal(t, i+1, count)
  23. }
  24. }