You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 lines
505 B

package retry
import (
"fmt"
"testing"
"time"
)
func TestRetryStep(t *testing.T) {
t.Logf("start retry: unix=%d", time.Now().Unix())
r, err := DoWithStepDelay(5, time.Second, func(retryTimes uint32) (uint32, error) {
t.Logf("retry %d times, unix=%d", retryTimes, time.Now().Unix())
if retryTimes < 4 {
return retryTimes, fmt.Errorf("test error: %d", retryTimes)
}
return retryTimes, nil
})
if err != nil {
t.Error(err)
return
}
if r != 4 {
t.Errorf("error result: %d", r)
}
}