Documentation ¶
Overview ¶
Package leaktest provides tools to detect leaked goroutines in tests. To use it, call "defer leaktest.Check(t)()" at the beginning of each test that may use goroutines. copied out of the cockroachdb source tree with slight modifications to be more re-useable
Index ¶
- Variables
- func Check(t ErrorReporter) func()
- func CheckContext(ctx context.Context, t ErrorReporter) func()
- func CheckTimeout(t ErrorReporter, dur time.Duration) func()
- func CostWith(fn func()) (dur time.Duration)
- func Count(n int) <-chan int
- func FuncSprint(args ...interface{}) string
- func Print(vs ...interface{})
- func PrintMemStats()
- func Println(vs ...interface{})
- func Range(min, max int) int
- func RangeBytes(min, max int) []byte
- func RangeDur(min, max time.Duration) time.Duration
- func RangeString(min, max int) string
- func SliceOf(args ...interface{}) []interface{}
- func String(v interface{}, options ...Option) string
- func TestFuncWith(fn interface{}) *xtest
- func Tick(args ...interface{}) <-chan time.Time
- func TimeoutWith(dur time.Duration, fn func()) error
- func Try(fn func()) (e error)
- func Wrap(fn interface{}) func(...interface{}) func(...interface{}) (err error)
- type B
- type ErrorReporter
- type Option
- type Printer
Constants ¶
This section is empty.
Variables ¶
var ( ErrXTest = xerror.New("xtest error") ErrParamIsNil = ErrXTest.New("the parameter is nil") ErrFuncTimeout = ErrXTest.New("the func is timeout") ErrParamTypeNotFunc = ErrXTest.New("the type of the parameters is not func") ErrDurZero = ErrXTest.New("the duration time must more than zero") ErrInputParamsNotMatch = ErrXTest.New("the input params of func is not match") ErrInputOutputParamsNotMatch = ErrXTest.New("the input num and output num of the callback func is not match") ErrFuncOutputTypeNotMatch = ErrXTest.New("the output type of the callback func is not match") ErrForeachParameterNil = ErrXTest.New("the parameter of [Foreach] must not be nil") )
var Default = New(os.Stdout, Indent(" "))
Default prints to os.Stdout with two space indentation.
var TickerInterval = time.Millisecond * 50
TickerInterval defines the interval used by the ticker in Check* functions.
Functions ¶
func Check ¶
func Check(t ErrorReporter) func()
Check snapshots the currently-running goroutines and returns a function to be run at the end of tests to see whether any goroutines leaked, waiting up to 5 seconds in error conditions
func CheckContext ¶ added in v0.1.12
func CheckContext(ctx context.Context, t ErrorReporter) func()
CheckContext is the same as Check, but uses a context.Context for cancellation and timeout control
func CheckTimeout ¶ added in v0.1.12
func CheckTimeout(t ErrorReporter, dur time.Duration) func()
CheckTimeout is the same as Check, but with a configurable timeout
func FuncSprint ¶ added in v0.1.2
func FuncSprint(args ...interface{}) string
func Print ¶ added in v0.1.13
func Print(vs ...interface{})
Print writes a representation of v to os.Stdout, separated by spaces.
func PrintMemStats ¶ added in v0.1.8
func PrintMemStats()
func Println ¶ added in v0.1.13
func Println(vs ...interface{})
Println prints v to os.Stdout, one per line.
func TestFuncWith ¶
func TestFuncWith(fn interface{}) *xtest
func TimeoutWith ¶
Types ¶
type B ¶ added in v0.1.8
type B struct {
// contains filtered or unexported fields
}
func (*B) CpuProfile ¶ added in v0.1.12
func (*B) MemProfile ¶ added in v0.1.12
func (*B) StartTimer ¶ added in v0.1.8
func (b *B) StartTimer()
StartTimer starts timing a test. This function is called automatically before a benchmark starts, but it can also be used to resume timing after a call to StopTimer.
type ErrorReporter ¶ added in v0.1.12
type ErrorReporter interface {
Errorf(format string, args ...interface{})
}
ErrorReporter is a tiny subset of a testing.TB to make testing not such a massive pain
type Option ¶ added in v0.1.13
type Option func(o *Printer)
An Option modifies the default behaviour of a Printer.
func AlwaysIncludeType ¶ added in v0.1.13
func AlwaysIncludeType() Option
AlwaysIncludeType always includes explicit type information for each item.
func Hide ¶ added in v0.1.13
func Hide(ts ...interface{}) Option
Hide excludes the given types from representation, instead just printing the name of the type.
func IgnoreGoStringer ¶ added in v0.1.13
func IgnoreGoStringer() Option
IgnoreGoStringer disables use of the .GoString() method.
type Printer ¶ added in v0.1.13
type Printer struct {
// contains filtered or unexported fields
}
Printer represents structs in a printable manner.