From 34397865b1174f4d4b33941877a5906e50965b3b Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Sat, 6 Dec 2025 10:09:38 -0500 Subject: [PATCH] runtime: deflake TestProfBufWakeup If CI infrastructure is oversubscribed, the profile buffer reader can be blocked long enough for the status in the traceback to be something like "[syscall, 3 minutes]", rather than the "[syscall]" we are looking for. Tweak the regexp to look for the expected state at the beginning of the status in the brackets. While we're here, clarify the possible "race" in the test, which has more to do with failing to catch a buggy implementation rather than failing for a correct implementation. Ideally if the implementation is buggy, we should see the t.Errorf at least some of the time, even if we don't see it in every run. Change-Id: Iebd5229d338dc3f973349cea6dd84c506a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/727660 Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- src/runtime/profbuf_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/runtime/profbuf_test.go b/src/runtime/profbuf_test.go index 2f068ac386..470c23dd41 100644 --- a/src/runtime/profbuf_test.go +++ b/src/runtime/profbuf_test.go @@ -232,11 +232,14 @@ func TestProfBufWakeup(t *testing.T) { // The reader shouldn't wake up for this b.Write(nil, 1, []uint64{1, 2}, []uintptr{3, 4}) - // The reader should still be blocked - // - // TODO(nick): this is racy. We could Gosched and still have the reader - // blocked in a buggy implementation because it just didn't get a chance - // to run + // The reader should still be blocked. The awaitBlockedGoroutine here + // checks that and also gives a buggy implementation a chance to + // actually wake up (it calls Gosched) before the next write. There is a + // small chance that a buggy implementation would have woken up but + // doesn't get scheduled by the time we do the next write. In that case + // the reader will see a more-than-half-full buffer and the test will + // pass. But if the implementation is broken, this test should fail + // regularly, even if not 100% of the time. awaitBlockedGoroutine(waitStatus, "TestProfBufWakeup.func1") b.Write(nil, 1, []uint64{5, 6}, []uintptr{7, 8}) b.Close() @@ -247,7 +250,8 @@ func TestProfBufWakeup(t *testing.T) { // see also runtime/pprof tests func awaitBlockedGoroutine(state, fName string) { - re := fmt.Sprintf(`(?m)^goroutine \d+ \[%s\]:\n(?:.+\n\t.+\n)*runtime_test\.%s`, regexp.QuoteMeta(state), fName) + // NB: this matches [state] as well as [state, n minutes] + re := fmt.Sprintf(`(?m)^goroutine \d+ \[%s.*\]:\n(?:.+\n\t.+\n)*runtime_test\.%s`, regexp.QuoteMeta(state), fName) r := regexp.MustCompile(re) buf := make([]byte, 64<<10) -- 2.52.0