mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
43 lines
685 B
Go
43 lines
685 B
Go
package fx
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRetry(t *testing.T) {
|
|
assert.NotNil(t, DoWithRetry(func() error {
|
|
return errors.New("any")
|
|
}))
|
|
|
|
var times int
|
|
assert.Nil(t, DoWithRetry(func() error {
|
|
times++
|
|
if times == defaultRetryTimes {
|
|
return nil
|
|
}
|
|
return errors.New("any")
|
|
}))
|
|
|
|
times = 0
|
|
assert.NotNil(t, DoWithRetry(func() error {
|
|
times++
|
|
if times == defaultRetryTimes+1 {
|
|
return nil
|
|
}
|
|
return errors.New("any")
|
|
}))
|
|
|
|
total := 2 * defaultRetryTimes
|
|
times = 0
|
|
assert.Nil(t, DoWithRetry(func() error {
|
|
times++
|
|
if times == total {
|
|
return nil
|
|
}
|
|
return errors.New("any")
|
|
}, WithRetry(total)))
|
|
}
|