You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/fx/retry_test.go

43 lines
688 B
Go

4 years ago
package fx
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRetry(t *testing.T) {
assert.NotNil(t, DoWithRetry(func() error {
4 years ago
return errors.New("any")
}))
var times int
assert.Nil(t, DoWithRetry(func() error {
4 years ago
times++
if times == defaultRetryTimes {
return nil
}
return errors.New("any")
}))
times = 0
assert.NotNil(t, DoWithRetry(func() error {
4 years ago
times++
if times == defaultRetryTimes+1 {
return nil
}
return errors.New("any")
}))
var total = 2 * defaultRetryTimes
times = 0
assert.Nil(t, DoWithRetry(func() error {
4 years ago
times++
if times == total {
return nil
}
return errors.New("any")
}, WithRetry(total)))
4 years ago
}