* 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
25 lines
502 B
Go
25 lines
502 B
Go
package retry
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func TestDo(t *testing.T) {
|
|
n := 4
|
|
for i := 0; i < n; i++ {
|
|
count := 0
|
|
err := Do(context.Background(), func(ctx context.Context, opts ...grpc.CallOption) error {
|
|
count++
|
|
return status.Error(codes.ResourceExhausted, "ResourceExhausted")
|
|
}, WithMax(i))
|
|
assert.Error(t, err)
|
|
assert.Equal(t, i+1, count)
|
|
}
|
|
}
|