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) } }