From 8ac0a7c512e7c1bf6fb94feb09b2f878d8eb14a1 Mon Sep 17 00:00:00 2001 From: Cosmos Nicolaou Date: Fri, 2 Feb 2024 17:12:27 -0800 Subject: [PATCH] runtime/pprof: continued attempt to deflake the VMInfo test. This PR will use test.Skip to bypass a test run for which the vmmap subprocess appears to hang before the test times out. In addition it catches a different error message from vmmap that can occur due to transient resource shortages and triggers a retry for this additional case. Fixes #62352 Change-Id: I3ae749e5cd78965c45b1b7c689b896493aa37ba0 Reviewed-on: https://go-review.googlesource.com/c/go/+/560935 Reviewed-by: Michael Pratt Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/runtime/pprof/vminfo_darwin_test.go | 34 +++++++++++++++++++------ 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/runtime/pprof/vminfo_darwin_test.go b/src/runtime/pprof/vminfo_darwin_test.go index 641587200c2..4c0a0fefd87 100644 --- a/src/runtime/pprof/vminfo_darwin_test.go +++ b/src/runtime/pprof/vminfo_darwin_test.go @@ -17,6 +17,7 @@ import ( "strconv" "strings" "testing" + "time" ) func TestVMInfo(t *testing.T) { @@ -56,18 +57,35 @@ func TestVMInfo(t *testing.T) { } } +type mapping struct { + hi, lo uint64 + err error +} + func useVMMapWithRetry(t *testing.T) (hi, lo uint64, err error) { var retryable bool - for { - hi, lo, retryable, err = useVMMap(t) - if err == nil { - return hi, lo, nil + ch := make(chan mapping) + go func() { + for { + hi, lo, retryable, err = useVMMap(t) + if err == nil { + ch <- mapping{hi, lo, nil} + return + } + if !retryable { + ch <- mapping{0, 0, err} + return + } + t.Logf("retrying vmmap after error: %v", err) } - if !retryable { - return 0, 0, err - } - t.Logf("retrying vmmap after error: %v", err) + }() + select { + case m := <-ch: + return m.hi, m.lo, m.err + case <-time.After(time.Minute): + t.Skip("vmmap taking too long") } + return 0, 0, fmt.Errorf("unreachable") } func useVMMap(t *testing.T) (hi, lo uint64, retryable bool, err error) {