From 72b31d6fdc68be2f0a1756b03f5ada71516eeca1 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 2 Feb 2016 21:01:21 -0800 Subject: [PATCH] pkg/testutil: more aggressive goroutine stack trace coalescing Strips out the pointer arguments in the header of the stack trace so that more stack traces match each other. --- pkg/testutil/leak.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/testutil/leak.go b/pkg/testutil/leak.go index d7bc26482..38ef4dc9d 100644 --- a/pkg/testutil/leak.go +++ b/pkg/testutil/leak.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "os" + "regexp" "runtime" "sort" "strings" @@ -42,17 +43,18 @@ func CheckLeakedGoroutine() bool { return false } gs := interestingGoroutines() - - n := 0 - stackCount := make(map[string]int) - for _, g := range gs { - stackCount[g]++ - n++ - } - - if n == 0 { + if len(gs) == 0 { return false } + + stackCount := make(map[string]int) + re := regexp.MustCompile("\\(0[0-9a-fx, ]*\\)") + for _, g := range gs { + // strip out pointer arguments in first function of stack dump + normalized := string(re.ReplaceAll([]byte(g), []byte("(...)"))) + stackCount[normalized]++ + } + fmt.Fprintf(os.Stderr, "Too many goroutines running after all test(s).\n") for stack, count := range stackCount { fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack)