Use available port for gRPC server tests #895
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
gRPC tests sometimes fail with this error:
This happens when we try to bind a gRPC server to new local endpoint that is already in use.
Given we hard-coded the ports, it is possible that another process will randomly choose to bind to these high ports by chance.
The best way to bind to an available local port is to bind to port
0
, letting the OS find a port for us, butGRPC::RpcServer
does not support that, raising an error instead when provided with0
.So we do the next best thing which is to find an available port ourselves and quickly hand it to gRPC. There's a very small chance that another process will bind to the port we just found available between the time we retrieve its number and hand it to gRPC, but there's no perfect solution with the APIs we are provided by the gem.