|
|
|
|
@ -8,7 +8,7 @@ import (
|
|
|
|
|
func TestRetry(t *testing.T) {
|
|
|
|
|
numTries := uint(0)
|
|
|
|
|
// Test that a passing function only gets called once.
|
|
|
|
|
err := Retry(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
err := Run(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
numTries++
|
|
|
|
|
return true, nil
|
|
|
|
|
})
|
|
|
|
|
@ -22,7 +22,7 @@ func TestRetry(t *testing.T) {
|
|
|
|
|
// Test that a failing function gets retried (once in this example).
|
|
|
|
|
numTries = 0
|
|
|
|
|
results := []bool{false, true}
|
|
|
|
|
err = Retry(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
err = Run(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
result := results[numTries]
|
|
|
|
|
numTries++
|
|
|
|
|
return result, nil
|
|
|
|
|
@ -37,7 +37,7 @@ func TestRetry(t *testing.T) {
|
|
|
|
|
// Test that a function error gets returned, and the function does not get called again.
|
|
|
|
|
numTries = 0
|
|
|
|
|
funcErr := fmt.Errorf("This function had an error!")
|
|
|
|
|
err = Retry(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
err = Run(0, 0, 0, func(i uint) (bool, error) {
|
|
|
|
|
numTries++
|
|
|
|
|
return false, funcErr
|
|
|
|
|
})
|
|
|
|
|
@ -51,7 +51,7 @@ func TestRetry(t *testing.T) {
|
|
|
|
|
// Test when a function exhausts its retries.
|
|
|
|
|
numTries = 0
|
|
|
|
|
expectedTries := uint(3)
|
|
|
|
|
err = Retry(0, 0, expectedTries, func(i uint) (bool, error) {
|
|
|
|
|
err = Run(0, 0, expectedTries, func(i uint) (bool, error) {
|
|
|
|
|
numTries++
|
|
|
|
|
return false, nil
|
|
|
|
|
})
|
|
|
|
|
|