From f553c95eeb29be1694c12eb8769c3531bb628f5d Mon Sep 17 00:00:00 2001 From: aarzilli Date: Mon, 14 Aug 2017 07:57:49 +0200 Subject: [PATCH] proc/tests: fix intermittent failure of TestNextParked Always pick a goroutine that we know will have to be resumed before the program terminates instead of relying on luck. Fixes #803 --- pkg/proc/proc_test.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 523775a4..e69c102b 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -1951,8 +1951,7 @@ func TestNextParked(t *testing.T) { // continue until a parked goroutine exists var parkedg *proc.G - LookForParkedG: - for { + for parkedg == nil { err := proc.Continue(p) if _, exited := err.(proc.ProcessExitedError); exited { t.Log("could not find parked goroutine") @@ -1963,10 +1962,24 @@ func TestNextParked(t *testing.T) { gs, err := proc.GoroutinesInfo(p) assertNoError(err, t, "GoroutinesInfo()") + // Search for a parked goroutine that we know for sure will have to be + // resumed before the program can exit. This is a parked goroutine that: + // 1. is executing main.sayhi + // 2. hasn't called wg.Done yet for _, g := range gs { - if g.Thread == nil { - parkedg = g - break LookForParkedG + if g.Thread != nil { + continue + } + frames, _ := g.Stacktrace(5) + for _, frame := range frames { + // line 11 is the line where wg.Done is called + if frame.Current.Fn != nil && frame.Current.Fn.Name == "main.sayhi" && frame.Current.Line < 11 { + parkedg = g + break + } + } + if parkedg != nil { + break } } }