diff options
| author | Russ Cox <rsc@golang.org> | 2016-01-06 21:16:01 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2016-01-13 01:46:01 +0000 |
| commit | fac8202c3ffdddf5d2b35a2c3620c1eb56018b9b (patch) | |
| tree | ec9ed1a66478563127a9faa17fe8764705692c6a /src/runtime/proc_test.go | |
| parent | 1e066cad1ba23f4064545355b8737e4762dd6838 (diff) | |
| download | go-fac8202c3ffdddf5d2b35a2c3620c1eb56018b9b.tar.xz | |
runtime: make NumGoroutine and Stack agree not to include system goroutines
[Repeat of CL 18343 with build fixes.]
Before, NumGoroutine counted system goroutines and Stack (usually) didn't show them,
which was inconsistent and confusing.
To resolve which way they should be consistent, it seems like
package main
import "runtime"
func main() { println(runtime.NumGoroutine()) }
should print 1 regardless of internal runtime details. Make it so.
Fixes #11706.
Change-Id: If26749fec06aa0ff84311f7941b88d140552e81d
Reviewed-on: https://go-review.googlesource.com/18432
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/proc_test.go')
| -rw-r--r-- | src/runtime/proc_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/runtime/proc_test.go b/src/runtime/proc_test.go index 30798f723d..f3e90bcbd7 100644 --- a/src/runtime/proc_test.go +++ b/src/runtime/proc_test.go @@ -9,6 +9,7 @@ import ( "net" "runtime" "runtime/debug" + "strings" "sync" "sync/atomic" "syscall" @@ -336,6 +337,23 @@ func TestGCFairness(t *testing.T) { } } +func TestNumGoroutine(t *testing.T) { + output := runTestProg(t, "testprog", "NumGoroutine") + want := "1\n" + if output != want { + t.Fatalf("want %q, got %q", want, output) + } + + buf := make([]byte, 1<<20) + buf = buf[:runtime.Stack(buf, true)] + + n := runtime.NumGoroutine() + + if nstk := strings.Count(string(buf), "goroutine "); n != nstk { + t.Fatalf("NumGoroutine=%d, but found %d goroutines in stack dump", n, nstk) + } +} + func TestPingPongHog(t *testing.T) { if testing.Short() { t.Skip("skipping in -short mode") |
