retryinterceptor_test.go 502 B

123456789101112131415161718192021222324
  1. package retry
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "google.golang.org/grpc"
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/status"
  9. )
  10. func TestDo(t *testing.T) {
  11. n := 4
  12. for i := 0; i < n; i++ {
  13. count := 0
  14. err := Do(context.Background(), func(ctx context.Context, opts ...grpc.CallOption) error {
  15. count++
  16. return status.Error(codes.ResourceExhausted, "ResourceExhausted")
  17. }, WithMax(i))
  18. assert.Error(t, err)
  19. assert.Equal(t, i+1, count)
  20. }
  21. }