-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
testing: T.Context usability concerns #18199
Comments
Issue #18182 was another person asking for this last night. Their motivation: #18182 (comment) |
#16221 is the proposal that added |
Copying here the point made in golang-dev, for clarity: Such a flagging mechanism that by definition will only be useful when things will continue running in the background past the test completion does feel like a wart to me. We should be discouraging people from doing that in the first place, because arbitrary background logic delayed for arbitrary periods of time while other things are being tested is a common source of testing pain, breaking in curious and hard to reproduce ways. As people pointed out, it's not a mere case of putting logic locally. The context, by definition, will only trigger code to start aborting after it's too late. An aborting yet running goroutine can do whatever it wants in order to attempt to stop cleanly. In my own testing, services generally have a Stop method because of that. Internally, they leverage a tomb to flag the stopping and block until everything is done cleaning themselves up. Stop also usually returns an error, so one can also check that the stop was itself clean. |
Summary of my thoughts. We should either:
I understand most uses of Some arguments against the status quo (i.e., only adding
If we go with adding a wait mechanism, I don't feel strongly whether it's by exposing a |
There is one benefit of adding So a minimal fix might be a |
I think canceling the The fact that people have differing expectations of when
|
Good point. Still, especially given the ability to create subtests I think there are a number of situations in which "cancel on first failure" really is what you want. But perhaps that argues for something more like |
Another data point. There are use-cases where we want to add graceful timeout to tests. The current implementation of |
If you want a timeout, you can make a derived context from t.Context(). Again, this isn't supposed to be the end-all Context for all imaginable use cases. It's supposed to be a convenience thing. And having a context available would've helped a CL I reviewed yesterday (https://go-review.googlesource.com/c/33972/1/http2/transport_test.go) if the context were available. But it was a few lines of code without t.Context, so we survived. But obvious you dislike it, so feel free to send a CL removing it and the documentation from go1.8.html. Perfect is the enemy of good. |
I'm uploading a CL to revert this change. There are a fair number of people who have reservations about this. The main argument for adding To be fair, I originally voted in favor of this change in #16221, but changed my position on this after trying to use it on several unit tests. I am personally still in support adding |
CL https://golang.org/cl/34141 mentions this issue. |
One possibility might be to add:
That way the test can at least wait for the goroutine to finish |
CL https://golang.org/cl/34242 mentions this issue. |
Fixes the build. Updates #18199 Change-Id: Ibf029ba9f9293d1f3d49c1c8773fc262159a5d5b Reviewed-on: https://go-review.googlesource.com/34242 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
CL https://golang.org/cl/34274 mentions this issue. |
Updates golang/go#11811 Updates golang/go#18199 Change-Id: I2ce4615653034563a64b9c126651d2a6ce2aef50 Reviewed-on: https://go-review.googlesource.com/34274 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
If the idea of |
https://groups.google.com/d/topic/golang-dev/rS6psxIf17Q/discussion
Decide on whether to keep/change/remove the API before the 1.8 release.
The text was updated successfully, but these errors were encountered: