Commit 40cd845e authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: improve test leak checker flakiness

And make it have more useful output on failure.

Update #5005

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/8016046
parent d1eb9c8e
...@@ -65,8 +65,6 @@ func afterTest(t *testing.T) { ...@@ -65,8 +65,6 @@ func afterTest(t *testing.T) {
if testing.Short() { if testing.Short() {
return return
} }
buf := make([]byte, 1<<20)
var stacks string
var bad string var bad string
badSubstring := map[string]string{ badSubstring := map[string]string{
").readLoop(": "a Transport", ").readLoop(": "a Transport",
...@@ -75,9 +73,10 @@ func afterTest(t *testing.T) { ...@@ -75,9 +73,10 @@ func afterTest(t *testing.T) {
"timeoutHandler": "a TimeoutHandler", "timeoutHandler": "a TimeoutHandler",
"net.(*netFD).connect(": "a timing out dial", "net.(*netFD).connect(": "a timing out dial",
} }
var stacks string
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
bad = "" bad = ""
stacks = string(buf[:runtime.Stack(buf, true)]) stacks = strings.Join(interestingGoroutines(), "\n\n")
for substr, what := range badSubstring { for substr, what := range badSubstring {
if strings.Contains(stacks, substr) { if strings.Contains(stacks, substr) {
bad = what bad = what
...@@ -90,6 +89,5 @@ func afterTest(t *testing.T) { ...@@ -90,6 +89,5 @@ func afterTest(t *testing.T) {
// shutting down, so give it some time. // shutting down, so give it some time.
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
} }
gs := interestingGoroutines() t.Errorf("Test appears to have leaked %s:\n%s", bad, stacks)
t.Errorf("Test appears to have leaked %s:\n%s", bad, strings.Join(gs, "\n\n"))
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment