Documentation ¶
Overview ¶
Package retry contains logic to retry actions with certain conditions.
Index ¶
- func DoWithRetry(t *testing.T, actionDescription string, maxRetries int, ...) string
- func DoWithRetryE(t *testing.T, actionDescription string, maxRetries int, ...) (string, error)
- func DoWithRetryableErrors(t *testing.T, actionDescription string, retryableErrors map[string]string, ...) string
- func DoWithRetryableErrorsE(t *testing.T, actionDescription string, retryableErrors map[string]string, ...) (string, error)
- func DoWithTimeout(t *testing.T, actionDescription string, timeout time.Duration, ...) string
- func DoWithTimeoutE(t *testing.T, actionDescription string, timeout time.Duration, ...) (string, error)
- type Done
- type Either
- type FatalError
- type MaxRetriesExceeded
- type TimeoutExceeded
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoWithRetry ¶
func DoWithRetry(t *testing.T, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) string
DoWithRetry runs the specified action. If it returns a value, return that value. If it returns a FatalError, return that error immediately. If it returns any other type of error, sleep for sleepBetweenRetries and try again, up to a maximum of maxRetries retries. If maxRetries is exceeded, fail the test.
func DoWithRetryE ¶
func DoWithRetryE(t *testing.T, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) (string, error)
DoWithRetryE runs the specified action. If it returns a value, return that value. If it returns a FatalError, return that error immediately. If it returns any other type of error, sleep for sleepBetweenRetries and try again, up to a maximum of maxRetries retries. If maxRetries is exceeded, return a MaxRetriesExceeded error.
func DoWithRetryableErrors ¶ added in v0.16.0
func DoWithRetryableErrors(t *testing.T, actionDescription string, retryableErrors map[string]string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) string
DoWithRetryableErrors runs the specified action. If it returns a value, return that value. If it returns an error, check if error message or the string output from the action (which is often stdout/stderr from running some command) matches any of the regular expressions in the specified retryableErrors map. If there is a match, sleep for sleepBetweenRetries, and retry the specified action, up to a maximum of maxRetries retries. If there is no match, return that error immediately, wrapped in a FatalError. If maxRetries is exceeded, return a MaxRetriesExceeded error.
func DoWithRetryableErrorsE ¶ added in v0.16.0
func DoWithRetryableErrorsE(t *testing.T, actionDescription string, retryableErrors map[string]string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) (string, error)
DoWithRetryableErrorsE runs the specified action. If it returns a value, return that value. If it returns an error, check if error message or the string output from the action (which is often stdout/stderr from running some command) matches any of the regular expressions in the specified retryableErrors map. If there is a match, sleep for sleepBetweenRetries, and retry the specified action, up to a maximum of maxRetries retries. If there is no match, return that error immediately, wrapped in a FatalError. If maxRetries is exceeded, return a MaxRetriesExceeded error.
func DoWithTimeout ¶
func DoWithTimeout(t *testing.T, actionDescription string, timeout time.Duration, action func() (string, error)) string
DoWithTimeout runs the specified action and waits up to the specified timeout for it to complete. Return the output of the action if it completes on time or fail the test otherwise.
func DoWithTimeoutE ¶
func DoWithTimeoutE(t *testing.T, actionDescription string, timeout time.Duration, action func() (string, error)) (string, error)
DoWithTimeoutE runs the specified action and waits up to the specified timeout for it to complete. Return the output of the action if it completes on time or an error otherwise.
Types ¶
type Done ¶
type Done struct {
// contains filtered or unexported fields
}
Done can be stopped.
func DoInBackgroundUntilStopped ¶
func DoInBackgroundUntilStopped(t *testing.T, actionDescription string, sleepBetweenRepeats time.Duration, action func()) Done
DoInBackgroundUntilStopped runs the specified action in the background (in a goroutine) repeatedly, waiting the specified amount of time between repetitions. To stop this action, call the Done() function on the returned value.
type FatalError ¶
type FatalError struct {
Underlying error
}
FatalError is a marker interface for errors that should not be retried.
func (FatalError) Error ¶
func (err FatalError) Error() string
type MaxRetriesExceeded ¶
MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded.
func (MaxRetriesExceeded) Error ¶
func (err MaxRetriesExceeded) Error() string
type TimeoutExceeded ¶
TimeoutExceeded is an error that occurs when a timeout is exceeded.
func (TimeoutExceeded) Error ¶
func (err TimeoutExceeded) Error() string