Skip to content

Commit fe4952f

Browse files
committed
runtime: relax threadsSlack in TestReadMetricsSched
runtime.GC is called in the test and may spin up GOMAXPROCS (proportional to the initial count) new threads. We need to be robust to this, and it happens relatively frequently on some platforms. We didn't notice this earlier since the heap is so miniscule that runtime.GC essentially finished instantly without all the threads getting spun up. Fixes #76613. Change-Id: I2af02cb090d5c1c952e4db53ad35895b6f23f638 Reviewed-on: https://go-review.googlesource.com/c/go/+/726642 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
1 parent 8947f09 commit fe4952f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/runtime/testdata/testprog/schedmetrics.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ func SchedMetrics() {
9191
// threads through frequent scheduling, like mayMoreStackPreempt.
9292
// A slack of 5 is arbitrary but appears to be enough to cover
9393
// the leftovers plus any inflation from scheduling-heavy build
94-
// modes.
95-
const threadsSlack = 5
94+
// modes. We then also add initialGMP to this slack, since we're
95+
// about to call runtime.GC, and in the worst case this will
96+
// spin up GOMAXPROCS new threads to run those workers.
97+
threadsSlack := 5 + uint64(initialGMP)
9698

9799
// Make sure GC isn't running, since GC workers interfere with
98100
// expected counts.

0 commit comments

Comments
 (0)