]> git.feebdaed.xyz Git - 0xmirror/go.git/commitdiff
runtime: deflake TestProfBufWakeup
authorNick Ripley <nick.ripley@datadoghq.com>
Sat, 6 Dec 2025 15:09:38 +0000 (10:09 -0500)
committerNick Ripley <nick.ripley@datadoghq.com>
Mon, 8 Dec 2025 15:46:16 +0000 (07:46 -0800)
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 <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/runtime/profbuf_test.go

index 2f068ac386ded861d83fae4a6e89ed0677f298b4..470c23dd419561af74cfcbb9e03db3c0924fdabd 100644 (file)
@@ -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)