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 PrintMemStats()
- 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 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
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 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 PrintMemStats ¶ added in v0.1.8
func PrintMemStats()
func TestFuncWith ¶
func TestFuncWith(fn interface{}) *xtest
func TimeoutWith ¶
Types ¶
type B ¶ added in v0.1.8
func BenchmarkParallel ¶ added in v0.1.12
Benchmark benchmarks a single function. It is useful for creating custom benchmarks that do not use the "go test" command.
If f depends on testing flags, then Init must be used to register those flags before calling Benchmark and before calling flag.Parse.
If f calls Run, the result will be an estimate of running all its subbenchmarks that don't call Run in sequence in a single benchmark.
func (*B) AllocBytes ¶ added in v0.1.12
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