Documentation
¶
Overview ¶
Package linger contains a utility for reporting on where lingering tasks were originally started.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckClean ¶
CheckClean will record a test error if there are any active tasks being tracked by the Recorder. A snapshot of the stack where the tasks were launched will be written into the test log.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
A Recorder can be attached to a stopper.Context to record the call stack where stopper.Context.Call or stopper.Context.Go has been called. See CheckClean for ways to use a Recorder in testing scenarios.
Example ¶
// Construct the recorder and attach it as task middleware. The
// stack depth counts away from Context.Call() or Context.Go(). If
// the package-level Call() or Go() helpers are used, the smallest
// useful depth is 2 frames.
rec := linger.NewRecorder(2 /* stack depth */)
ctx := stopper.New(
stopper.WithTaskOptions(
stopper.TaskMiddleware(rec.Middleware),
))
defer ctx.Stop()
// Start some tasks.
_ = stopper.Go(ctx, func(ctx stopper.Context) {
<-ctx.Stopping()
})
// Sample the tasks asynchronously.
stacks := rec.Callers()
for _, stack := range stacks {
frames := runtime.CallersFrames(stack)
for {
frame, more := frames.Next()
fmt.Println(frame.Function)
if !more {
break
}
}
}
Output: vawter.tech/stopper/v2.Go[...] vawter.tech/stopper/v2/linger_test.ExampleRecorder
func NewRecorder ¶
NewRecorder constructs a Recorder that samples the call stack at the requested depth. A depth of 1 will record the location at which stopper.Context.Call or stopper.Context.Go was executed.
func (*Recorder) Callers ¶
Callers returns a snapshot of the caller stacks associated with any managed tasks that are currently running.
func (*Recorder) Middleware ¶
Middleware is a stopper.Middleware that samples the caller to stopper.Context.Call or to stopper.Context.Go.
type TestingT ¶
TestingT is the subset of testing.TB needed by CheckClean.