Documentation ¶
Index ¶
- Variables
- func AssertDuration(t *testing.T, expectedDuration int, actualDuration time.Duration)
- func ErrorNTimesThenError[R any](err error, errorTimes int, finalError error) func(failsafe.Execution[R]) (R, error)
- func ErrorNTimesThenPanic[R any](err error, errorTimes int, panicValue any) func(failsafe.Execution[R]) (R, error)
- func ErrorNTimesThenReturn[R any](err error, errorTimes int, results ...R) (fn func(failsafe.Execution[R]) (R, error), resetFn func())
- func GetFn[R any](result R, err error) func(failsafe.Execution[R]) (R, error)
- func GetType(myvar interface{}) string
- func GrpcClient(dialer Dialer, options ...grpc.DialOption) *grpc.ClientConn
- func MillisToNanos(millis int) int64
- func MockDelayedGrpcResponse(response string, delay time.Duration) pbfixtures.PingServiceServer
- func MockDelayedResponse(statusCode int, body string, delay time.Duration) *httptest.Server
- func MockFlakyGrpcServer(failTimes int, err error, finalResponse string) pbfixtures.PingServiceServer
- func MockFlakyServer(failTimes int, responseCode int, retryAfterDelay time.Duration, ...) (server *httptest.Server, resetFailures func())
- func MockGrpcError(err error) pbfixtures.PingServiceServer
- func MockGrpcResponses(responses ...string) pbfixtures.PingServiceServer
- func MockResponse(statusCode int, body string) *httptest.Server
- func RunFn(err error) func(failsafe.Execution[any]) error
- func SetupWithContextSleep(sleepTime time.Duration) func() context.Context
- func Timed(fn func()) time.Duration
- func WaitAndAssertCanceled[R any](t *testing.T, waitDuration time.Duration, exec failsafe.Execution[R])
- type AssertFunc
- type CompositeError
- type ContextFn
- type CustomError
- type Dialer
- type MultiError
- type Resetable
- type TestClock
- type TestExecution
- func (e TestExecution[R]) AttemptStartTime() time.Time
- func (e TestExecution[R]) Attempts() int
- func (e TestExecution[R]) Canceled() <-chan struct{}
- func (e TestExecution[R]) Context() context.Context
- func (e TestExecution[R]) ElapsedAttemptTime() time.Duration
- func (e TestExecution[R]) ElapsedTime() time.Duration
- func (e TestExecution[R]) Executions() int
- func (e TestExecution[R]) Hedges() int
- func (e TestExecution[R]) IsCanceled() bool
- func (e TestExecution[R]) IsFirstAttempt() bool
- func (e TestExecution[R]) IsHedge() bool
- func (e TestExecution[R]) IsRetry() bool
- func (e TestExecution[R]) LastError() error
- func (e TestExecution[R]) LastResult() R
- func (e TestExecution[R]) Retries() int
- func (e TestExecution[R]) StartTime() time.Time
- type TestStopwatch
- type Tester
- func (t *Tester[R]) AssertFailure(expectedAttempts int, expectedExecutions int, expectedError error, ...)
- func (t *Tester[R]) AssertFailureAs(expectedAttempts int, expectedExecutions int, expectedError error, ...)
- func (t *Tester[R]) AssertSuccess(expectedAttempts int, expectedExecutions int, expectedResult R, then ...func())
- func (t *Tester[R]) AssertSuccessError(expectedAttempts int, expectedExecutions int, expectedError error, ...)
- func (t *Tester[R]) Context(fn func() context.Context) *Tester[R]
- func (t *Tester[R]) Get(when WhenGet[R]) *Tester[R]
- func (t *Tester[R]) Reset(stats ...Resetable) *Tester[R]
- func (t *Tester[R]) Run(when WhenRun[R]) *Tester[R]
- func (t *Tester[R]) Setup(fn func()) *Tester[R]
- func (t *Tester[R]) With(policies ...failsafe.Policy[R]) *Tester[R]
- func (t *Tester[R]) WithExecutor(executor failsafe.Executor[R]) *Tester[R]
- type Waiter
- type WhenGet
- type WhenRun
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidArgument = errors.New("invalid argument") ErrInvalidState = errors.New("invalid state") ErrConnecting = errors.New("connection error") NoopFn = func() error { return nil } GetFalseFn = func() (bool, error) { return false, nil } GetTrueFn = func() (bool, error) { return true, nil } )
View Source
var CanceledContextFn = func() context.Context { ctx, cancel := context.WithCancel(context.Background()) cancel() return ctx }
Functions ¶
func AssertDuration ¶
func ErrorNTimesThenError ¶
func ErrorNTimesThenError[R any](err error, errorTimes int, finalError error) func(failsafe.Execution[R]) (R, error)
ErrorNTimesThenError returns a stub function that returns the err errorTimes and then returns the finalError. Can be used with failsafe.GetWithExecution.
func ErrorNTimesThenPanic ¶
func ErrorNTimesThenPanic[R any](err error, errorTimes int, panicValue any) func(failsafe.Execution[R]) (R, error)
ErrorNTimesThenPanic returns a stub function that returns the err errorTimes and then panics with the panicValue. Can be used with failsafe.GetWithExecution.
func ErrorNTimesThenReturn ¶
func ErrorNTimesThenReturn[R any](err error, errorTimes int, results ...R) (fn func(failsafe.Execution[R]) (R, error), resetFn func())
ErrorNTimesThenReturn returns a stub function that returns the err errorTimes and then returns the results. Can be used with failsafe.GetWithExecution.
func GrpcClient ¶ added in v0.6.5
func GrpcClient(dialer Dialer, options ...grpc.DialOption) *grpc.ClientConn
func MillisToNanos ¶
func MockDelayedGrpcResponse ¶ added in v0.6.5
func MockDelayedGrpcResponse(response string, delay time.Duration) pbfixtures.PingServiceServer
func MockDelayedResponse ¶ added in v0.6.0
func MockFlakyGrpcServer ¶ added in v0.6.5
func MockFlakyGrpcServer(failTimes int, err error, finalResponse string) pbfixtures.PingServiceServer
func MockFlakyServer ¶ added in v0.6.2
func MockGrpcError ¶ added in v0.6.5
func MockGrpcError(err error) pbfixtures.PingServiceServer
func MockGrpcResponses ¶ added in v0.6.5
func MockGrpcResponses(responses ...string) pbfixtures.PingServiceServer
func SetupWithContextSleep ¶ added in v0.3.1
SetupWithContextSleep returns a setup function that provides a context that is canceled after the sleepTime.
Types ¶
type AssertFunc ¶ added in v0.6.5
type AssertFunc[R any] func(expectedAttempts int, expectedExecutions int, expectedResult R, result R, expectedErr error, err error, expectedSuccess bool, expectedFailure bool, errorAs bool, thens ...func())
func PrepareTest ¶ added in v0.6.2
func PrepareTest[R any](t *testing.T, setupFn func(), contextFn ContextFn, executor failsafe.Executor[R]) (executorFn func() failsafe.Executor[R], assertFn AssertFunc[R])
type CompositeError ¶
type CompositeError struct {
Cause error
}
func (CompositeError) Error ¶
func (e CompositeError) Error() string
func (CompositeError) Unwrap ¶
func (e CompositeError) Unwrap() error
type CustomError ¶ added in v0.6.7
type CustomError struct{ Msg string }
func (CustomError) Error ¶ added in v0.6.7
func (e CustomError) Error() string
type Dialer ¶ added in v0.6.5
func GrpcServer ¶ added in v0.6.5
func GrpcServer(service pbfixtures.PingServiceServer, options ...grpc.ServerOption) (*grpc.Server, Dialer)
type MultiError ¶ added in v0.6.7
type MultiError []error
func (MultiError) Error ¶ added in v0.6.7
func (e MultiError) Error() string
func (MultiError) Unwrap ¶ added in v0.6.7
func (e MultiError) Unwrap() []error
type TestExecution ¶
func (TestExecution[R]) AttemptStartTime ¶
func (e TestExecution[R]) AttemptStartTime() time.Time
func (TestExecution[R]) Attempts ¶
func (e TestExecution[R]) Attempts() int
func (TestExecution[R]) Canceled ¶
func (e TestExecution[R]) Canceled() <-chan struct{}
func (TestExecution[R]) Context ¶ added in v0.3.1
func (e TestExecution[R]) Context() context.Context
func (TestExecution[R]) ElapsedAttemptTime ¶
func (e TestExecution[R]) ElapsedAttemptTime() time.Duration
func (TestExecution[R]) ElapsedTime ¶
func (e TestExecution[R]) ElapsedTime() time.Duration
func (TestExecution[R]) Executions ¶
func (e TestExecution[R]) Executions() int
func (TestExecution[R]) Hedges ¶ added in v0.5.0
func (e TestExecution[R]) Hedges() int
func (TestExecution[R]) IsCanceled ¶
func (e TestExecution[R]) IsCanceled() bool
func (TestExecution[R]) IsFirstAttempt ¶
func (e TestExecution[R]) IsFirstAttempt() bool
func (TestExecution[R]) IsHedge ¶ added in v0.5.0
func (e TestExecution[R]) IsHedge() bool
func (TestExecution[R]) IsRetry ¶
func (e TestExecution[R]) IsRetry() bool
func (TestExecution[R]) LastError ¶
func (e TestExecution[R]) LastError() error
func (TestExecution[R]) LastResult ¶
func (e TestExecution[R]) LastResult() R
func (TestExecution[R]) Retries ¶ added in v0.5.0
func (e TestExecution[R]) Retries() int
func (TestExecution[R]) StartTime ¶
func (e TestExecution[R]) StartTime() time.Time
type TestStopwatch ¶
type TestStopwatch struct {
CurrentTime int64
}
func (*TestStopwatch) ElapsedTime ¶
func (t *TestStopwatch) ElapsedTime() time.Duration
func (*TestStopwatch) Reset ¶
func (t *TestStopwatch) Reset()
type Tester ¶ added in v0.6.3
type Tester[R any] struct { T *testing.T SetupFn func() ContextFn Executor failsafe.Executor[R] // contains filtered or unexported fields }
func (*Tester[R]) AssertFailure ¶ added in v0.6.3
func (*Tester[R]) AssertFailureAs ¶ added in v0.6.7
func (*Tester[R]) AssertSuccess ¶ added in v0.6.3
func (*Tester[R]) AssertSuccessError ¶ added in v0.6.3
func (*Tester[R]) WithExecutor ¶ added in v0.6.3
type Waiter ¶
type Waiter struct {
// contains filtered or unexported fields
}
func (*Waiter) AssertEqual ¶
func (*Waiter) AwaitWithTimeout ¶
Click to show internal directories.
Click to hide internal directories.