Documentation
¶
Overview ¶
Package leakcheck contains functions to check leaked goroutines and buffers.
Call the following at the beginning of test:
defer leakcheck.NewLeakChecker(t).Check()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckGoroutines ¶ added in v1.66.0
CheckGoroutines looks at the currently-running goroutines and checks if there are any interesting (created by gRPC) goroutines leaked. It waits up to 10 seconds in the error cases.
func CheckTimers ¶ added in v1.72.0
CheckTimers undoes the effects of TrackTimers, and fails unit tests if not all timers were cancelled or executed. It is invalid to invoke this function without previously having invoked TrackTimers.
func CheckTrackingBufferPool ¶ added in v1.66.0
func CheckTrackingBufferPool()
CheckTrackingBufferPool undoes the effects of SetTrackingBufferPool, and fails unit tests if not all buffers were returned. It is invalid to invoke this function without previously having invoked SetTrackingBufferPool.
func RegisterIgnoreGoroutine ¶
func RegisterIgnoreGoroutine(s string)
RegisterIgnoreGoroutine appends s into the ignore goroutine list. The goroutines whose stack trace contains s will not be identified as leaked goroutines. Not thread-safe, only call this function in init().
func SetTrackingBufferPool ¶ added in v1.66.0
func SetTrackingBufferPool(logger Logger)
SetTrackingBufferPool replaces the default buffer pool in the mem package to one that tracks where buffers are allocated. CheckTrackingBufferPool should then be invoked at the end of the test to validate that all buffers pulled from the pool were returned.
func TrackTimers ¶ added in v1.72.0
func TrackTimers()
TrackTimers replaces internal.TimerAfterFunc with one that tracks timer creations, stoppages and expirations. CheckTimers should then be invoked at the end of the test to validate that all timers created have either executed or are cancelled.
Types ¶
type LeakChecker ¶ added in v1.66.0
type LeakChecker struct {
// contains filtered or unexported fields
}
LeakChecker captures a Logger and is returned by NewLeakChecker as a convenient method to set up leak check tests in a unit test.
func NewLeakChecker ¶ added in v1.66.0
func NewLeakChecker(logger Logger) *LeakChecker
NewLeakChecker offers a convenient way to set up the leak checks for a specific unit test. It can be used as follows, at the beginning of tests:
defer leakcheck.NewLeakChecker(t).Check()
It initially invokes SetTrackingBufferPool to set up buffer tracking, then the deferred LeakChecker.Check call will invoke CheckTrackingBufferPool and CheckGoroutines with a default timeout of 10 seconds.