retry

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 5 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.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 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.

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