failpoint

package
v1.6.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package failpoint provides the code point in the path, which can be controlled by user's variable.

Inspired by FreeBSD fail(9): https://freebsd.org/cgi/man.cgi?query=fail.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvalFn

type EvalFn func() error

EvalFn is the func type about delegated evaluation.

type Failpoint

type Failpoint struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Failpoint is used to add code points where error or panic may be injected by user. The user controlled variable will be parsed for how the error injected code should fire. There is the way to set the rule for failpoint.

<count>*<type>[(arg)][-><more terms>]

The <type> argument specifies which action to take; it can be one of:

off:	Takes no action (does not trigger failpoint and no argument)
error:	Triggers failpoint error with specified argument(string)
panic:	Triggers panic with specified argument(string)
delay:	Sleep the specified number of milliseconds

The <count>* modifiers prior to <type> control when <type> is executed. For example, "5*error(oops)" means "return error oops 5 times total". The operator -> can be used to express cascading terms. If you specify <term1>-><term2>, it means that if <term1> does not execute, <term2> will be evaluated. If you want the error injected code should fire in second call, you can specify "1*off->1*error(oops)".

Inspired by FreeBSD fail(9): https://freebsd.org/cgi/man.cgi?query=fail.

func NewFailpoint

func NewFailpoint(fnName string, terms string) (*Failpoint, error)

NewFailpoint returns failpoint control.

func (*Failpoint) DelegatedEval

func (fp *Failpoint) DelegatedEval() EvalFn

DelegatedEval evaluates a failpoint but delegates to caller to fire that.

func (*Failpoint) Evaluate

func (fp *Failpoint) Evaluate() error

Evaluate evaluates a failpoint.

func (*Failpoint) Marshal

func (fp *Failpoint) Marshal() string

Failpoint returns the current state of control in string format.

type Type

type Type int

Type is the type of failpoint to specifies which action to take.

const (
	// TypeInvalid is invalid type
	TypeInvalid Type = iota
	// TypeOff takes no action
	TypeOff
	// TypeError triggers failpoint error with specified argument
	TypeError
	// TypePanic triggers panic with specified argument
	TypePanic
	// TypeDelay sleeps with the specified number of milliseconds
	TypeDelay
)

func (Type) String

func (t Type) String() string

String returns the name of type.

Jump to

Keyboard shortcuts

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