runtime: don't artificially limit TestReadMetricsSched

TestReadMetricsSched/running can take some time to enter in steady state
on busy systems. We currently only allow 1 second for that, we should
let it run unlimitedly until success or the test time's out.

Fixes #75049

Change-Id: I452059e1837caf12a2d2d9cae1f70a0ef2d4f518
Reviewed-on: https://go-review.googlesource.com/c/go/+/702295
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
qmuntal 2025-09-10 08:23:42 +02:00 committed by Gopher Robot
parent b1f3e38e41
commit fad1dc608d

View file

@ -1632,15 +1632,13 @@ func TestReadMetricsSched(t *testing.T) {
checkEq := func(t *testing.T, s *metrics.Sample, value uint64) { checkEq := func(t *testing.T, s *metrics.Sample, value uint64) {
check(t, s, value, value) check(t, s, value, value)
} }
spinUntil := func(f func() bool, timeout time.Duration) bool { spinUntil := func(f func() bool) bool {
start := time.Now() for {
for time.Since(start) < timeout {
if f() { if f() {
return true return true
} }
time.Sleep(time.Millisecond) time.Sleep(50 * time.Millisecond)
} }
return false
} }
// Check base values. // Check base values.
@ -1693,12 +1691,12 @@ func TestReadMetricsSched(t *testing.T) {
t.Run("running", func(t *testing.T) { t.Run("running", func(t *testing.T) {
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(count + 4)) defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(count + 4))
// It can take a little bit for the scheduler to // It can take a little bit for the scheduler to
// distribute the goroutines to Ps, so retry for a // distribute the goroutines to Ps, so retry until
// while. // we see the count we expect or the test times out.
spinUntil(func() bool { spinUntil(func() bool {
metrics.Read(s[:]) metrics.Read(s[:])
return s[running].Value.Uint64() >= count return s[running].Value.Uint64() >= count
}, time.Second) })
logMetrics(t, s[:]) logMetrics(t, s[:])
check(t, &s[running], count, count+4) check(t, &s[running], count, count+4)
check(t, &s[threads], count, count+4+threadsSlack) check(t, &s[threads], count, count+4+threadsSlack)
@ -1761,7 +1759,7 @@ func TestReadMetricsSched(t *testing.T) {
spinUntil(func() bool { spinUntil(func() bool {
metrics.Read(s[:]) metrics.Read(s[:])
return s[notInGo].Value.Uint64() >= count return s[notInGo].Value.Uint64() >= count
}, time.Second) })
metrics.Read(s[:]) metrics.Read(s[:])
logMetrics(t, s[:]) logMetrics(t, s[:])
@ -1783,7 +1781,7 @@ func TestReadMetricsSched(t *testing.T) {
spinUntil(func() bool { spinUntil(func() bool {
metrics.Read(s[:]) metrics.Read(s[:])
return s[waiting].Value.Uint64() >= waitingCount return s[waiting].Value.Uint64() >= waitingCount
}, time.Second) })
metrics.Read(s[:]) metrics.Read(s[:])
logMetrics(t, s[:]) logMetrics(t, s[:])