From bc77ff4534a29727a42c61effd35f3e822202e14 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 19 Jan 2018 15:42:23 +0100 Subject: [PATCH] proc_test: deflake TestSystemstackOnRuntimeNewstack (#1078) Depending on how the runtime schedules our goroutines we can get unlucky and have the first call to runtime.newstack we intercept be for a different goroutine (usually the garbage collector). Only check stacktraces that happen on the same goroutine that executed main.main. --- pkg/proc/proc_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 04a6f518..0849b184 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -3365,11 +3365,21 @@ func TestSystemstackOnRuntimeNewstack(t *testing.T) { _, err := setFunctionBreakpoint(p, "main.main") assertNoError(err, t, "setFunctionBreakpoint(main.main)") assertNoError(proc.Continue(p), t, "first continue") - _, err = setFunctionBreakpoint(p, "runtime.newstack") - assertNoError(err, t, "setFunctionBreakpoint(runtime.newstack)") - assertNoError(proc.Continue(p), t, "second continue") + g, err := proc.GetG(p.CurrentThread()) assertNoError(err, t, "GetG") + mainGoroutineID := g.ID + + _, err = setFunctionBreakpoint(p, "runtime.newstack") + assertNoError(err, t, "setFunctionBreakpoint(runtime.newstack)") + for { + assertNoError(proc.Continue(p), t, "second continue") + g, err = proc.GetG(p.CurrentThread()) + assertNoError(err, t, "GetG") + if g.ID == mainGoroutineID { + break + } + } frames, err := g.Stacktrace(100) assertNoError(err, t, "stacktrace") logStacktrace(t, frames)