MCPcopy Create free account
hub / github.com/fortytw2/leaktest

github.com/fortytw2/leaktest @v1.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.0 ↗ · + Follow
21 symbols 48 edges 3 files 7 documented · 33% 13 cross-repo links updated 5y agov1.3.0 · 2018-11-09★ 1,0453 open issues

Browse by type

Functions 17 Types & classes 4
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Leaktest Build Status codecov Sourcegraph Documentation

Refactored, tested variant of the goroutine leak detector found in both net/http tests and the cockroachdb source tree.

Takes a snapshot of running goroutines at the start of a test, and at the end - compares the two and voila. Ignores runtime/sys goroutines. Doesn't play nice with t.Parallel() right now, but there are plans to do so.

Installation

Go 1.7+

go get -u github.com/fortytw2/leaktest

Go 1.5/1.6 need to use the tag v1.0.0, as newer versions depend on context.Context.

Example

These tests fail, because they leak a goroutine

// Default "Check" will poll for 5 seconds to check that all
// goroutines are cleaned up
func TestPool(t *testing.T) {
    defer leaktest.Check(t)()

    go func() {
        for {
            time.Sleep(time.Second)
        }
    }()
}

// Helper function to timeout after X duration
func TestPoolTimeout(t *testing.T) {
    defer leaktest.CheckTimeout(t, time.Second)()

    go func() {
        for {
            time.Sleep(time.Second)
        }
    }()
}

// Use Go 1.7+ context.Context for cancellation
func TestPoolContext(t *testing.T) {
    ctx, _ := context.WithTimeout(context.Background(), time.Second)
    defer leaktest.CheckContext(ctx, t)()

    go func() {
        for {
            time.Sleep(time.Second)
        }
    }()
}

LICENSE

Same BSD-style as Go, see LICENSE

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 12
Method 5
Struct 2
Interface 1
TypeAlias 1

Languages

Go100%

Modules by API surface

leaktest.go12 symbols
leaktest_test.go7 symbols
leaktest_utils_test.go2 symbols

For agents

$ claude mcp add leaktest \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page