Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: testing: add TB.SetGOMAXPROCS #62020

Open
sivchari opened this issue Aug 14, 2023 · 2 comments
Open

proposal: testing: add TB.SetGOMAXPROCS #62020

sivchari opened this issue Aug 14, 2023 · 2 comments
Labels
Milestone

Comments

@sivchari
Copy link
Contributor

I propose adding a SetGOMAXPROCS. This idea is inspired by TB.Setenv.

As seen Go source codes, too, if it sets GOMAXPROCS and it unsets this value after cleanup, we must write the following ways.

defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(n))
prev := runtime.GOMAXPROCS(n)
defer runtime.GOMAXPROCS(prev)

The writing style is general, if you know Go specification. But I think we can provide better way to achieve.

I submitted a CL. If this CL isn't been necessary, I don't mind to close it. Thanks.

@gopherbot gopherbot added this to the Proposal milestone Aug 14, 2023
@carlmjohnson
Copy link
Contributor

Does this come up very often? You can also define a third party helper like

func MaxProcs(t testing.TB, n int) {
  prev := runtime.GOMAXPROCS(n)
  t.Cleanup(func() { runtime.GOMAXPROCS(prev) })
}

// in a test
testhelpers.MaxProcs(t, 1)

@gopherbot
Copy link

Change https://go.dev/cl/519235 mentions this issue: testing: add TB.SetGOMAXPROCS function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Incoming
Development

No branches or pull requests

3 participants