retryinterceptor_test.go 724 B

12345678910111213141516171819202122232425262728
  1. package clientinterceptors
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/tal-tech/go-zero/core/retry"
  7. "google.golang.org/grpc"
  8. "google.golang.org/grpc/codes"
  9. "google.golang.org/grpc/status"
  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,
  18. opts ...grpc.CallOption) error {
  19. count++
  20. return status.Error(codes.ResourceExhausted, "ResourceExhausted")
  21. }, retry.WithMax(i))
  22. assert.Error(t, err)
  23. assert.Equal(t, i+1, count)
  24. }
  25. }