From: Michael Anthony Knyszek Date: Mon, 22 Sep 2025 17:36:03 +0000 (+0000) Subject: runtime: don't re-read metrics before check in TestReadMetricsSched X-Git-Tag: go1.26rc1~817 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e23edf5e55703cc6ddbb86a198a35487b34d863b;p=gostls13.git runtime: don't re-read metrics before check in TestReadMetricsSched The two remaining popular flakes in TestReadMetricsSched are with waiting and not-in-go goroutines. I believe the reason for both of these is pollution due to other goroutines in the test binary, and we can be a little bit more robust to them. In particular, both of these tests spin until there's a particular condition met in the metrics. Then they both immediately re-read the metrics. The metrics being checked are not guaranteed to stay that way in the re-read. For example, for the waiting case, it's possible for >1000 to be waiting, but then some leftover goroutines from a previous test wake up off of some condition, causing the number to dip again on the re-read. This is supported by the fact that in some of these failures, the test takes very little time to execute (the condition that there are at least 1000 waiting goroutines is almost immediately satisfied) but it still fails (the re-read causes us to notice that there are <1000 waiting goroutines). This change makes the test more robust by not performing this re-read. This means more possible false negatives, but the error cases we're looking for (bad metrics) should still show up with some reasonable probability when something *is* truly wrong. For #75049. Change-Id: Idc3a8030bed8da51f24322efe15f3ff13da05623 Reviewed-on: https://go-review.googlesource.com/c/go/+/705875 Reviewed-by: Michael Pratt Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI --- diff --git a/src/runtime/metrics_test.go b/src/runtime/metrics_test.go index 3989b79293..af042f4445 100644 --- a/src/runtime/metrics_test.go +++ b/src/runtime/metrics_test.go @@ -1760,8 +1760,6 @@ func TestReadMetricsSched(t *testing.T) { metrics.Read(s[:]) return s[notInGo].Value.Uint64() >= count }) - - metrics.Read(s[:]) logMetrics(t, s[:]) check(t, &s[notInGo], count, count+generalSlack) @@ -1782,8 +1780,6 @@ func TestReadMetricsSched(t *testing.T) { metrics.Read(s[:]) return s[waiting].Value.Uint64() >= waitingCount }) - - metrics.Read(s[:]) logMetrics(t, s[:]) check(t, &s[waiting], waitingCount, waitingCount+waitingSlack)