Documentation ¶
Index ¶
- func Break(label ...string)
- func Continue(label ...string)
- func Disable(failpath string) error
- func Enable(failpath, inTerms string) error
- func EnableWith(failpath, inTerms string, action func() error) error
- func Fallthrough()
- func Goto(label string)
- func Inject(fpname string, fpbody interface{})
- func InjectContext(ctx context.Context, fpname string, fpbody interface{})
- func Label(label string)
- func List() []string
- func Return(result ...interface{})
- func Status(failpath string) (string, error)
- func WithHook(ctx context.Context, hook Hook) context.Context
- type Failpoint
- type Failpoints
- func (fps *Failpoints) Disable(failpath string) error
- func (fps *Failpoints) Enable(failpath, inTerms string) error
- func (fps *Failpoints) EnableWith(failpath, inTerms string, action func() error) error
- func (fps *Failpoints) Eval(failpath string) (Value, error)
- func (fps *Failpoints) EvalContext(ctx context.Context, failpath string) (Value, error)
- func (fps *Failpoints) List() []string
- func (fps *Failpoints) Status(failpath string) (string, error)
- type FpError
- type Hook
- type HookKey
- type HttpHandler
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Break ¶
func Break(label ...string)
Break will generate a break statement in a loop, e.g: case1:
for i := 0; i < max; i++ { failpoint.Inject("break-if-index-equal-2", func() { if i == 2 { failpoint.Break() } } }
failpoint.Break() => break
case2:
outer: for i := 0; i < max; i++ { for j := 0; j < max / 2; j++ { failpoint.Inject("break-if-index-i-equal-j", func() { if i == j { failpoint.Break("outer") } } } }
failpoint.Break("outer") => break outer
func Continue ¶
func Continue(label ...string)
Continue will generate a continue statement the same as `failpoint.Break()`
func EnableWith ¶
EnableWith enables and locks the failpoint, the lock prevents the failpoint to be evaluated. It invokes the action while holding the lock. It is useful when enables a panic failpoint and does some post actions before the failpoint being evaluated.
func Goto ¶
func Goto(label string)
Goto will generate a goto statement the same as `failpoint.Break()`
func Inject ¶
func Inject(fpname string, fpbody interface{})
Inject marks a fail point routine, which will be rewrite to a `if` statement and be triggered by fail point name specified `fpname` Note: The fail point closure parameter type can only be `failpoint.Value` e.g: failpoint.Inject("fail-point-name", func() (...){} failpoint.Inject("fail-point-name", func(val failpoint.Value) (...){} failpoint.Inject("fail-point-name", func(_ failpoint.Value) (...){}
func InjectContext ¶
InjectContext marks a fail point routine, which will be rewrite to a `if` statement and be triggered by fail point name specified `fpname` Note: The fail point closure parameter type can only be `failpoint.Value` e.g: failpoint.InjectContext(ctx, "fail-point-name", func() (...){} failpoint.InjectContext(ctx, "fail-point-name", func(val failpoint.Value) (...){} failpoint.InjectContext(ctx, "fail-point-name", func(_ failpoint.Value) (...){}
func Label ¶
func Label(label string)
Label will generate a label statement, e.g. case1:
failpoint.Label("outer") for i := 0; i < max; i++ { for j := 0; j < max / 2; j++ { failpoint.Inject("break-if-index-i-equal-j", func() { if i == j { failpoint.Break("outer") } } } }
failpoint.Label("outer") => outer: failpoint.Break("outer") => break outer
Types ¶
type Failpoint ¶
type Failpoint struct {
// contains filtered or unexported fields
}
Failpoint is a point to inject a failure
func (*Failpoint) EnableWith ¶
EnableWith enables and locks the failpoint, the lock prevents the failpoint to be evaluated. It invokes the action while holding the lock. It is useful when enables a panic failpoint and does some post actions before the failpoint being evaluated.
type Failpoints ¶
type Failpoints struct {
// contains filtered or unexported fields
}
Failpoints manages multiple failpoints
func (*Failpoints) Disable ¶
func (fps *Failpoints) Disable(failpath string) error
Disable a failpoint on failpath
func (*Failpoints) Enable ¶
func (fps *Failpoints) Enable(failpath, inTerms string) error
Enable a failpoint on failpath
func (*Failpoints) EnableWith ¶
func (fps *Failpoints) EnableWith(failpath, inTerms string, action func() error) error
EnableWith enables and locks the failpoint, the lock prevents the failpoint to be evaluated. It invokes the action while holding the lock. It is useful when enables a panic failpoint and does some post actions before the failpoint being evaluated.
func (*Failpoints) Eval ¶
func (fps *Failpoints) Eval(failpath string) (Value, error)
Eval evaluates a failpoint's value, It will return the evaluated value and true if the failpoint is active
func (*Failpoints) EvalContext ¶
EvalContext evaluates a failpoint's value, and calls hook if the context is not nil and contains hook function. It will return the evaluated value and true if the failpoint is active. Always returns false if ctx is nil or context does not contains a hook function
func (*Failpoints) List ¶
func (fps *Failpoints) List() []string
List returns all the failpoints information
type FpError ¶
type FpError error
FpError is the internal error of failpoint
var ( // ErrNotExist represents a failpoint can not be found by specified name ErrNotExist FpError = fmt.Errorf("failpoint: failpoint does not exist") // ErrDisabled represents a failpoint is be disabled ErrDisabled FpError = fmt.Errorf("failpoint: failpoint is disabled") // ErrNoContext returns by EvalContext when the context is nil ErrNoContext FpError = fmt.Errorf("failpoint: no context") // ErrNoHook returns by EvalContext when there is no hook in the context ErrNoHook FpError = fmt.Errorf("failpoint: no hook") // ErrFiltered represents a failpoint is filtered by a hook function ErrFiltered FpError = fmt.Errorf("failpoint: filtered by hook") // ErrNotAllowed represents a failpoint can not be executed this time ErrNotAllowed FpError = fmt.Errorf("failpoint: not allowed") )
type Hook ¶
Hook is used to filter failpoint, if the hook returns false and the failpoint will not to be evaluated.
type HookKey ¶
type HookKey string
HookKey represents the type of failpoint hook function key in context
type HttpHandler ¶
type HttpHandler struct{}
HttpHandler is used to handle failpoint Enable/Disable/Status requests
func (*HttpHandler) ServeHTTP ¶
func (*HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Value ¶
type Value interface{}
Value represents value that retrieved from failpoint terms. It can be used as following types: 1. val.(int) // GO_FAILPOINTS="failpoint-name=return(1)" 2. val.(string) // GO_FAILPOINTS="failpoint-name=return(\"1\")" 3. val.(bool) // GO_FAILPOINTS="failpoint-name=return(true)"
func Eval ¶
Eval evaluates a failpoint's value, It will return the evaluated value and nil err if the failpoint is active
func EvalContext ¶
EvalContext evaluates a failpoint's value, and calls hook if the context is not nil and contains hook function. It will return the evaluated value and true if the failpoint is active. Always returns false if ctx is nil or context does not contains hook function