aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2016-02-02 10:15:34 -0500
committerRuss Cox <rsc@golang.org>2016-02-02 16:36:21 +0000
commit1c6a35b4fe894ab0dc229be35d8a5fb0080a31d6 (patch)
treec85be909dcb5415758a199a2eb0f6777e499d6f7
parentf309bf3eeff8343e557a9798e42ac72b37da3f0a (diff)
downloadgo-1c6a35b4fe894ab0dc229be35d8a5fb0080a31d6.tar.gz
go-1c6a35b4fe894ab0dc229be35d8a5fb0080a31d6.zip
runtime: deflake TestGoroutineProfileTrivial
Failed at https://storage.googleapis.com/go-build-log/9875de36/nacl-amd64p32_931ba6cf.log Change-Id: I2bc204ed58da543ee2534b69c29c8e8485d54683 Reviewed-on: https://go-review.googlesource.com/19155 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/runtime/runtime_test.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go
index 581f52bcb0..a6150a77ee 100644
--- a/src/runtime/runtime_test.go
+++ b/src/runtime/runtime_test.go
@@ -310,13 +310,22 @@ func TestAppendSliceGrowth(t *testing.T) {
}
func TestGoroutineProfileTrivial(t *testing.T) {
- n1, ok := GoroutineProfile(nil) // should fail, there's at least 1 goroutine
- if n1 < 1 || ok {
- t.Fatalf("GoroutineProfile(nil) = %d, %v, want >0, false", n1, ok)
- }
-
- n2, ok := GoroutineProfile(make([]StackRecord, n1))
- if n2 != n1 || !ok {
- t.Fatalf("GoroutineProfile(%d) = %d, %v, want %d, true", n1, n2, ok, n1)
+ // Calling GoroutineProfile twice in a row should find the same number of goroutines,
+ // but it's possible there are goroutines just about to exit, so we might end up
+ // with fewer in the second call. Try a few times; it should converge once those
+ // zombies are gone.
+ for i := 0; ; i++ {
+ n1, ok := GoroutineProfile(nil) // should fail, there's at least 1 goroutine
+ if n1 < 1 || ok {
+ t.Fatalf("GoroutineProfile(nil) = %d, %v, want >0, false", n1, ok)
+ }
+ n2, ok := GoroutineProfile(make([]StackRecord, n1))
+ if n2 == n1 && ok {
+ break
+ }
+ t.Logf("GoroutineProfile(%d) = %d, %v, want %d, true", n1, n2, ok, n1)
+ if i >= 10 {
+ t.Fatalf("GoroutineProfile not converging")
+ }
}
}