-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: remove or improve T.FailNow #24680
Comments
I vote for option 0. How would (1) work, in practice? Every It sounds like (2) would require action from users to opt into the correct thing, so it wouldn't directly prevent the same misuse that happens today. I still think we should do #15758. AFAICT that thread doesn't actually contain any reasons why it's infeasible. I don't see why the testing package can't use horrible hacks as long as they're hidden in its implementation. I've seen this mistake many, many times while reviewing Go code. |
Personally, I would probably use
Agreed. |
Option (2) is still missing some sort of synchronization. If we terminate the test, how do we prevent it from interfering with other tests? In particular, how do we distinguish goroutines started by lazy library initialization from goroutines associated with the test function itself? |
We should revisit #15758 and complain loudly when FailNow is called from the wrong goroutine. If we're willing to go further then we should just do os.Exit(1) on such an illegal invocation. The test is basically unsalvageable at this point and the whole thing should just die. If that's too far for Go 1 then it should be considered for Go 2. Either way we should still make FailNow complain in Go 1. It'll save a lot of pain. |
Exactly, that doesn't even require exposing goroutine IDs, which is what stalled the original discussion. |
I believe there are two independent questions that this issue conflates:
These questions can be addressed independently. We could just permit |
Such a documentation change won't fix any of the problems caused by calling FailNow outside of the test. This seems like a bad option. |
Let's just do #15758. |
The "fatal only for main goroutine" nature of
T.FailNow
is a source of bugs when writing tests. We should either remove it or improve it's usability for Go 2. See issues #24678, #15758.Option 0:
Make misuse complain loudly. Rejected in #15758.
Option 1:
Just remove it (along with its friends
Fatal
andFatalf
). WhetherSkipNow
,Skip
,Skipf
are removed is possible too. With them gone, there is no temptation to misuse it.Option 2:
Expand the functionality of
FailNow
to be callable from any goroutine. The behavior would be such that it tears down only the goroutine it is called form and also cancels aContext
. Other goroutines can synchronize of the context for their own termination. This presumes thatContexts
are added totesting
. See #18368 (comment). This option can be done in Go 1.\cc @neild @bcmills @ash2k
The text was updated successfully, but these errors were encountered: