]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add a known goroutine, don't check goroutine leaks in benchmark mode
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Jun 2017 19:32:36 +0000 (19:32 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Jun 2017 20:37:53 +0000 (20:37 +0000)
Change-Id: I8aa070f8093e80ba19f0546d7447caf847a2b388
Reviewed-on: https://go-review.googlesource.com/45912
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/http/main_test.go

index fc0437e21155b7d8c540c8269b5ea69b44467c39..230ebaacfb46b029e340b9e6fa332005078d45ed 100644 (file)
@@ -37,6 +37,7 @@ func interestingGoroutines() (gs []string) {
                }
                stack := strings.TrimSpace(sl[1])
                if stack == "" ||
+                       strings.Contains(stack, "os/signal.signal_recv") ||
                        strings.Contains(stack, "created by net.startServer") ||
                        strings.Contains(stack, "created by testing.RunTests") ||
                        strings.Contains(stack, "closeWriteAndWait") ||
@@ -56,8 +57,9 @@ func interestingGoroutines() (gs []string) {
 
 // Verify the other tests didn't leave any goroutines running.
 func goroutineLeaked() bool {
-       if testing.Short() {
-               // not counting goroutines for leakage in -short mode
+       if testing.Short() || runningBenchmarks() {
+               // Don't worry about goroutine leaks in -short mode or in
+               // benchmark mode. Too distracting when there are false positives.
                return false
        }
 
@@ -92,6 +94,18 @@ func setParallel(t *testing.T) {
        }
 }
 
+func runningBenchmarks() bool {
+       for i, arg := range os.Args {
+               if strings.HasPrefix(arg, "-test.bench=") && !strings.HasSuffix(arg, "=") {
+                       return true
+               }
+               if arg == "-test.bench" && i < len(os.Args)-1 && os.Args[i+1] != "" {
+                       return true
+               }
+       }
+       return false
+}
+
 func afterTest(t testing.TB) {
        http.DefaultTransport.(*http.Transport).CloseIdleConnections()
        if testing.Short() {