// TestRetryFuncError tests an error inside the retried func. func TestRetryFuncError(t *testing.T) { assert := audit.NewTestingAssertion(t, true) err := timex.Retry(func() (bool, error) { return false, errors.New("ouch") }, timex.ShortAttempt()) assert.ErrorMatch(err, "ouch") }
// TestRetrySuccess tests a successful retry. func TestRetrySuccess(t *testing.T) { assert := audit.NewTestingAssertion(t, true) count := 0 err := timex.Retry(func() (bool, error) { count++ return count == 5, nil }, timex.ShortAttempt()) assert.Nil(err) assert.Equal(count, 5) }
// TestRetryTooOften tests a retry count error. func TestRetryTooOften(t *testing.T) { assert := audit.NewTestingAssertion(t, true) rs := timex.RetryStrategy{ Count: 5, Break: 5 * time.Millisecond, BreakIncrement: 5 * time.Millisecond, Timeout: time.Second, } err := timex.Retry(func() (bool, error) { return false, nil }, rs) assert.ErrorMatch(err, ".* retried more than .* times") }