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 · 6 comments
Open

proposal: testing: add TB.SetGOMAXPROCS #62020

sivchari opened this issue Aug 14, 2023 · 6 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
@earthboundkid
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
Contributor

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

@earthboundkid

This comment was marked as resolved.

@ianlancetaylor
Copy link
Contributor

That CL should not have been committed. My mistake. Sent a revert.

@gopherbot
Copy link
Contributor

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

@sivchari
Copy link
Contributor Author

sivchari commented Mar 22, 2024

@earthboundkid @ianlancetaylor

I thank you for working. I want to discuss whether this new API is necessary.
When the time comes to review this proposal, please discuss this with me.
Thanks again.

gopherbot pushed a commit that referenced this issue Mar 22, 2024
This reverts CL 519235.

Reason for revert: Proposal is still in incoming.

For #62020

Change-Id: Icccb930209f36097f5d930c01eda6b5042bdddc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/573516
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
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

4 participants