ReportFilenameWithPath controls whether to show call locations in leak reports by default in abbreviated form with only source code filename with package name and line number, or alternatively with source code filename with path and line number.
That is, with ReportFilenameWithPath==false:
foo/bar.go:123
Or with ReportFilenameWithPath==true:
/home/goworld/coolprojects/mymodule/foo/bar.go:123
var ReportFilenameWithPath = false
func HaveLeaked(ignoring ...interface{}) types.GomegaMatcher
HaveLeaked succeeds (or rather, "suckceeds" considering it appears in failing tests) if after filtering out ("ignoring") the expected goroutines from the list of actual goroutines the remaining list of goroutines is non-empty. These goroutines not filtered out are considered to have been leaked.
For convenience, HaveLeaked automatically filters out well-known runtime and testing goroutines using a built-in standard filter matchers list. In addition to the built-in filters, HaveLeaked accepts an optional list of non-leaky goroutine filter matchers. These filtering matchers can be specified in different formats, as described below.
Since there might be "pending" goroutines at the end of tests that eventually will properly wind down so they aren't leaking, HaveLeaked is best paired with Eventually instead of Expect. In its shortest form this will use Eventually's default timeout and polling interval settings, but these can be overridden as usual:
// Remember to use "Goroutines" and not "Goroutines()" with Eventually()! Eventually(Goroutines).ShouldNot(HaveLeaked()) Eventually(Goroutines).WithTimeout(5 * time.Second).ShouldNot(HaveLeaked())
In its simplest form, an expected non-leaky goroutine can be identified by passing the (fully qualified) name (in form of a string) of the topmost function in the backtrace. For instance:
Eventually(Goroutines).ShouldNot(HaveLeaked("foo.bar"))
This is the shorthand equivalent to this explicit form:
Eventually(Goroutines).ShouldNot(HaveLeaked(IgnoringTopFunction("foo.bar")))
HaveLeak also accepts passing a slice of Goroutine objects to be considered non-leaky goroutines.
snapshot := Goroutines() DoSomething() Eventually(Goroutines).ShouldNot(HaveLeaked(snapshot))
Again, this is shorthand for the following explicit form:
snapshot := Goroutines() DoSomething() Eventually(Goroutines).ShouldNot(HaveLeaked(IgnoringGoroutines(snapshot)))
Finally, HaveLeaked accepts any GomegaMatcher and will repeatedly pass it a Goroutine object: if the matcher succeeds, the Goroutine object in question is considered to be non-leaked and thus filtered out. While the following built-in Goroutine filter matchers should hopefully cover most situations, any suitable GomegaMatcher can be used for tricky leaky Goroutine filtering.
IgnoringTopFunction("foo.bar") IgnoringTopFunction("foo.bar...") IgnoringTopFunction("foo.bar [chan receive]") IgnoringGoroutines(expectedGoroutines) IgnoringInBacktrace("foo.bar.baz")
func IgnoreGinkgoParallelClient()
IgnoreGinkgoParallelClient must be called in a BeforeSuite whenever a test suite is run in parallel with other test suites using "ginkgo -p". Calling IgnoreGinkgoParallelClient checks for a Ginkgo-related background go routine and then updates gleak's internal ignore list to specifically ignore this background go routine by its ("random") ID.
func IgnoringCreator(creatorfname string) types.GomegaMatcher
IgnoringCreator succeeds if the goroutine was created by a function matching the specified name. The expected creator function name is either in the form of "creatorfunction-name" or "creatorfunction-name...".
An ellipsis "..." after a creatorfunction-name matches any creator function name if creatorfunction-name is a prefix and the goroutine's creator function name is at least one level deeper. For instance, "foo.bar..." matches "foo.bar.baz", but doesn't match "foo.bar".
func IgnoringGoroutines(goroutines []Goroutine) types.GomegaMatcher
IgnoringGoroutines succeeds if an actual goroutine, identified by its ID, is in a slice of expected goroutines. A typical use of the IgnoringGoroutines matcher is to take a snapshot of the current goroutines just right before a test and then at the end of a test filtering out these "good" and known goroutines.
func IgnoringInBacktrace(fname string) types.GomegaMatcher
IgnoringInBacktrace succeeds if a function name is contained in the backtrace of the actual goroutine description.
func IgnoringTopFunction(topfname string) types.GomegaMatcher
IgnoringTopFunction succeeds if the topmost function in the backtrace of an actual goroutine has the specified function name, and optionally the actual goroutine has the specified goroutine state.
The expected top function name topfn is either in the form of "topfunction-name", "topfunction-name...", or "topfunction-name [state]".
An ellipsis "..." after a topfunction-name matches any goroutine's top function name if topfunction-name is a prefix and the goroutine's top function name is at least one level deeper. For instance, "foo.bar..." matches "foo.bar.baz", but doesn't match "foo.bar".
If the optional expected state is specified, then a goroutine's state needs to start with this expected state text. For instance, "foo.bar [running]" matches a goroutine where the name of the top function is "foo.bar" and the goroutine's state starts with "running".
Goroutine represents information about a single goroutine and is a convenience type alias.
type Goroutine = goroutine.Goroutine
func G(actual interface{}, matchername string) (Goroutine, error)
G takes an actual "any" untyped value and returns it as a typed Goroutine, if possible. It returns an error if actual isn't of either type Goroutine or a pointer to it. G is intended to be mainly used by goroutine-related Gomega matchers, such as IgnoringTopFunction, et cetera.
func Goroutines() []Goroutine
Goroutines returns information about all goroutines: their goroutine IDs, the names of the topmost functions in the backtraces, and finally the goroutine backtraces.
HaveLeakedMatcher implements the HaveLeaked Gomega Matcher that succeeds if the actual list of goroutines is non-empty after filtering out the expected goroutines.
type HaveLeakedMatcher struct {
// contains filtered or unexported fields
}
func (matcher *HaveLeakedMatcher) FailureMessage(actual interface{}) (message string)
FailureMessage returns a failure message if there are leaked goroutines.
func (matcher *HaveLeakedMatcher) Match(actual interface{}) (success bool, err error)
Match succeeds if actual is an array or slice of Goroutine information and still contains goroutines after filtering out all expected goroutines that were specified when creating the matcher.
func (matcher *HaveLeakedMatcher) NegatedFailureMessage(actual interface{}) (message string)
NegatedFailureMessage returns a negated failure message if there aren't any leaked goroutines.
Uint64Slice implements the sort.Interface for a []uint64 to sort in increasing order.
type Uint64Slice []uint64
func (s Uint64Slice) Len() int
func (s Uint64Slice) Less(a, b int) bool
func (s Uint64Slice) Swap(a, b int)