-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
grpctest: new package #2186
grpctest: new package #2186
Conversation
Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement. After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.
Regards, |
I don't know why that CLA check is firing. I should be covered by the Google corporate CLA. |
// NewServer returns a new unstarted Server. | ||
// Attach RPC services to s.GRPC, then invoke s.Start to start the server. | ||
// The caller should call the Server's Close method when finished. | ||
func NewServer(t *testing.T) *Server { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This uses and encourages an anti-pattern for Go testing, which is passing testing.T
s around (which is particularly discouraged when crossing package boundaries and storing in structs AIUI).
Further, I'm not convinced this package is worth the extra API surface it introduces. It is easy to start and stop a server/client with grpc. The main complexity is the Listen
-on-localhost problem (which really should be solved in the net
package itself, but that's irrelevant here). In the not-too-distant future (~1Q or so), we should be introducing an in-process transport that will be even easier to serve/dial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to pass around testing.T
in limited circumstances. That's why t.Helper
exists, after all. It solves the problems that passing around a testing.T
produces.
It may be easy to start and stop a server for people like us who know what's going on, but lots of people aren't so comfortable. I see a lot of people getting it wrong in various ways (e.g. binding to :0
instead of a loopback address, or starting the server before registering service handlers). It's not a lot of code, but it cuts down the error rate a lot.
This is a problem with Go, though, not grpc; binding to :0 is/should be a loopback address. net.Listen should work with it. This is presumably golang/go#22826.
This approach wouldn't help solve that problem, though.
Let's wait until we have a real in-process transport, and write a doc on "how to start test servers & clients". It should be pretty short right now and even shorter then - not significant enough to justify a new library to maintain IMO. |
You can say that binding to An in-process transport seems like a fine direction (though then you miss out on testing with the OS's network code, so your test becomes less representative), but note that my proposed code here actually makes it easier to switch over to that and people don't have to specifically use some in-process transport in their tests but rather grpc-go will handle it for them. I don't think there's much to maintain here; it's very similar to the Google-internal rpctest package that I wrote, and it had only about 10 notable changes in 6 years. But if you really don't want this package, that's fine, it's your call; I'll leave it in my own project and then nobody else can benefit from it. |
This package makes some of the setup and teardown simpler and more reliable for test of code that interacts with gRPC servers. It is non-trivial to write this code in a way that is portable (across OS types, across supported network interface types, etc.). This change also demonstrates grpctest's use in the roundrobin test.
Let's revisit this after the in-process transport functionality is in place. I think once we have that, the process for starting/connecting to a service in tests should be just as simple as this package provides. |
This package makes some of the setup and teardown simpler and more
reliable for test of code that interacts with gRPC servers. It is
non-trivial to write this code in a way that is portable (across OS
types, across supported network interface types, etc.).
This change also demonstrates grpctest's use in the roundrobin test.