-
Notifications
You must be signed in to change notification settings - Fork 3.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
testing: unify context usage in tests #14220
Comments
Is the only argument against I'll cast a vote for incurring the diff noise; I found the lack of context-creation consistency to be the most confusing part of our context system. Also, it looks like there's a chance that testing.T.Context() returns in Go 1.9. |
I think it would be a good change because it will give us the flexibility to do something smarter with |
In the 5 months since this issue was filed, no plan has emerged for doing anything smarter with contexts in tests (nor, as far as I've seen, has there been any need that might drive such a plan). For curiosity's sake, we currently have slightly more instances of context.Background than context.TODO in tests (and relatively few uses of either outside of tests):
|
I maintain my opinion that the TODO in |
But what's the "better than Background()" alternative that these TODOs are waiting for? It's silly to have a style rule that mandates the use of context.TODO in brand new code. And we don't really lose anything by switching to context.Background - when/if we decide on a better context strategy for tests, the choice of context we make today won't make any difference on how easy or hard that will be to adopt. |
Plus, the documentation for
|
Let me turn the question around - why is |
|
My only contribution to what seems to me like a 🚲 🏚 is that we should just use |
Exactly, you are creating (deriving) a context, you're not just using I think To Tobi I'd say that reserving |
It doesn't matter much either way. I'm ok with |
Well I guess it's likely I'll lose a vote, so if whoever wants to drive this still has the desire... |
Seems like Background won. |
See discussion in #14128.
Currently, we have a mixture of
context.Background
andcontext.TODO
calls scattered throughout our tests. It's unclear which one to use, and no pattern has formed. There are good arguments for and against using both.context.Background
is the standard recommended usage for tests and is the convention adopted by most Go project, but implies that the context usage is a resolved question. Meanwhile,context.TODO
implies that future work is desired and helps keep unresolved context decisions separate from fully resolved ones, but is primarily meant for locations which we plan on fixing later by plumbing in a real context.@RaduBerinde further elaborated on this:
We should either fully adopt
context.Background
in tests as recommended by the Go documentation or replace all contexts in tests with some per-test context. Either way,context.TODO
should not sit in our tests forever.cc. @andreimatei @RaduBerinde @tamird
The text was updated successfully, but these errors were encountered: