retry

package
v0.0.0-...-07c49c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package retry contains logic to retry actions with certain conditions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoWithRetry

func DoWithRetry(t testing.TestingT, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) string

DoWithRetry runs the specified action. If it returns a string, return that string. 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.TestingT, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (string, error)) (string, error)

DoWithRetryE runs the specified action. If it returns a string, return that string. 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 DoWithRetryInterface

func DoWithRetryInterface(t testing.TestingT, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (interface{}, error)) interface{}

DoWithRetryInterface 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 DoWithRetryInterfaceE

func DoWithRetryInterfaceE(t testing.TestingT, actionDescription string, maxRetries int, sleepBetweenRetries time.Duration, action func() (interface{}, error)) (interface{}, error)

DoWithRetryInterfaceE 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

func DoWithRetryableErrors(t testing.TestingT, 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

func DoWithRetryableErrorsE(t testing.TestingT, 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.TestingT, 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.TestingT, 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.TestingT, 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.

func (Done) Done

func (done Done) Done()

Done stops the execution.

type Either

type Either struct {
	Result string
	Error  error
}

Either contains a result and potentially an error.

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

type MaxRetriesExceeded struct {
	Description string
	MaxRetries  int
}

MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded.

func (MaxRetriesExceeded) Error

func (err MaxRetriesExceeded) Error() string

type TimeoutExceeded

type TimeoutExceeded struct {
	Description string
	Timeout     time.Duration
}

TimeoutExceeded is an error that occurs when a timeout is exceeded.

func (TimeoutExceeded) Error

func (err TimeoutExceeded) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL