summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2014-09-22 09:13:09 -0400
committerBrad Fitzpatrick <bradfitz@golang.org>2014-09-22 09:13:09 -0400
commit15d3ea7250636ca9fb65930a4ba1422184afea85 (patch)
treeaa43ca8c23ee8b7c43dccd6ecfe5cffeed6500c1 /src/net
parent9f2888b329b4551e45245c3b3fdb881cb55945d9 (diff)
downloadgo-15d3ea7250636ca9fb65930a4ba1422184afea85.tar.gz
net/http: replace z_last_test hack with testing.Main
LGTM=adg R=rsc, adg CC=golang-codereviews https://codereview.appspot.com/144240043
Diffstat (limited to 'src/net')
-rw-r--r--src/net/http/main_test.go (renamed from src/net/http/z_last_test.go)30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/net/http/z_last_test.go b/src/net/http/main_test.go
index 5a0cc1198..9f1dfc372 100644
--- a/src/net/http/z_last_test.go
+++ b/src/net/http/main_test.go
@@ -5,7 +5,9 @@
package http_test
import (
+ "fmt"
"net/http"
+ "os"
"runtime"
"sort"
"strings"
@@ -13,6 +15,14 @@ import (
"time"
)
+func TestMain(m *testing.M) {
+ v := m.Run()
+ if v == 0 && goroutineLeaked() {
+ os.Exit(1)
+ }
+ os.Exit(v)
+}
+
func interestingGoroutines() (gs []string) {
buf := make([]byte, 2<<20)
buf = buf[:runtime.Stack(buf, true)]
@@ -30,6 +40,7 @@ func interestingGoroutines() (gs []string) {
// These only show up with GOTRACEBACK=2; Issue 5005 (comment 28)
strings.Contains(stack, "runtime.goexit") ||
strings.Contains(stack, "created by runtime.gc") ||
+ strings.Contains(stack, "net/http_test.interestingGoroutines") ||
strings.Contains(stack, "runtime.MHeap_Scavenger") {
continue
}
@@ -40,10 +51,10 @@ func interestingGoroutines() (gs []string) {
}
// Verify the other tests didn't leave any goroutines running.
-// This is in a file named z_last_test.go so it sorts at the end.
-func TestGoroutinesRunning(t *testing.T) {
+func goroutineLeaked() bool {
if testing.Short() {
- t.Skip("not counting goroutines for leakage in -short mode")
+ // not counting goroutines for leakage in -short mode
+ return false
}
gs := interestingGoroutines()
@@ -54,13 +65,14 @@ func TestGoroutinesRunning(t *testing.T) {
n++
}
- t.Logf("num goroutines = %d", n)
- if n > 0 {
- t.Error("Too many goroutines.")
- for stack, count := range stackCount {
- t.Logf("%d instances of:\n%s", count, stack)
- }
+ if n == 0 {
+ return false
+ }
+ fmt.Fprintf(os.Stderr, "Too many goroutines running after net/http test(s).\n")
+ for stack, count := range stackCount {
+ fmt.Fprintf(os.Stderr, "%d instances of:\n%s", count, stack)
}
+ return true
}
func afterTest(t *testing.T) {