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

grpctest: new package #2186

Closed
wants to merge 1 commit into from
Closed

grpctest: new package #2186

wants to merge 1 commit into from

Conversation

dsymonds
Copy link
Contributor

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.

@thelinuxfoundation
Copy link

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,
CLA GitHub bot

@dsymonds
Copy link
Contributor Author

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 {
Copy link
Member

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.Ts 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.

Copy link
Contributor Author

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.

@dfawley
Copy link
Member

dfawley commented Jun 28, 2018

I see a lot of people getting it wrong in various ways (e.g. binding to :0 instead of a loopback address

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.

or starting the server before registering service handlers

This approach wouldn't help solve that problem, though.

It's not a lot of code, but it cuts down the error rate a lot.

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.

@dsymonds
Copy link
Contributor Author

You can say that binding to :0 is a Go problem not a grpc problem (though I don't know how you'd then listen on all interfaces), but from the perspective of a user of grpc-go that is a distinction without a difference. The fact is that people get it wrong, and the point of having common libraries is to make it harder to get things like that wrong.

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.
@dfawley
Copy link
Member

dfawley commented Sep 5, 2018

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.

@dfawley dfawley closed this Sep 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants