Example #1
0
// 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")
}
Example #2
0
// 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)
}
Example #3
0
// 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")
}