(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func afterTest(t *testing.T) { |
| 43 | http.DefaultTransport.(*http.Transport).CloseIdleConnections() |
| 44 | if testing.Short() { |
| 45 | return |
| 46 | } |
| 47 | var bad string |
| 48 | badSubstring := map[string]string{ |
| 49 | ").readLoop(": "a Transport", |
| 50 | ").writeLoop(": "a Transport", |
| 51 | "created by net/http/httptest.(*Server).Start": "an httptest.Server", |
| 52 | "timeoutHandler": "a TimeoutHandler", |
| 53 | "net.(*netFD).connect(": "a timing out dial", |
| 54 | ").noteClientGone(": "a closenotifier sender", |
| 55 | } |
| 56 | var stacks string |
| 57 | for i := 0; i < 4; i++ { |
| 58 | bad = "" |
| 59 | stacks = strings.Join(interestingGoroutines(), "\n\n") |
| 60 | for substr, what := range badSubstring { |
| 61 | if strings.Contains(stacks, substr) { |
| 62 | bad = what |
| 63 | } |
| 64 | } |
| 65 | if bad == "" { |
| 66 | return |
| 67 | } |
| 68 | // Bad stuff found, but goroutines might just still be |
| 69 | // shutting down, so give it some time. |
| 70 | time.Sleep(250 * time.Millisecond) |
| 71 | } |
| 72 | t.Errorf("Test appears to have leaked %s:\n%s", bad, stacks) |
| 73 | } |
no test coverage detected