Skip to content

Commit

Permalink
Update gRPC and fix tests (#27)
Browse files Browse the repository at this point in the history
Combines the two open PRs so the tests pass and we don't depend on
outdated gRPC internals.
  • Loading branch information
JackWink authored and bwplotka committed Sep 12, 2018
1 parent 67591eb commit d5b35f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions proxy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/transport"
)

var (
Expand Down Expand Up @@ -60,11 +59,10 @@ type handler struct {
// forwarding it to a ClientStream established against the relevant ClientConn.
func (s *handler) handler(srv interface{}, serverStream grpc.ServerStream) error {
// little bit of gRPC internals never hurt anyone
lowLevelServerStream, ok := transport.StreamFromContext(serverStream.Context())
fullMethodName, ok := grpc.MethodFromServerStream(serverStream)
if !ok {
return grpc.Errorf(codes.Internal, "lowLevelServerStream not exists in context")
}
fullMethodName := lowLevelServerStream.Method()
// We require that the director's returned context inherits from the serverStream.Context().
outgoingCtx, backendConn, err := s.director(serverStream.Context(), fullMethodName)
clientCtx, clientCancel := context.WithCancel(outgoingCtx)
Expand Down
4 changes: 2 additions & 2 deletions proxy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s *ProxyHappySuite) TestPingCarriesServerHeadersAndTrailers() {
out, err := s.testClient.Ping(s.ctx(), &pb.PingRequest{Value: "foo"}, grpc.Header(&headerMd), grpc.Trailer(&trailerMd))
require.NoError(s.T(), err, "Ping should succeed without errors")
require.Equal(s.T(), &pb.PingResponse{Value: "foo", Counter: 42}, out)
assert.Len(s.T(), headerMd, 1, "server response headers must contain server data")
assert.Contains(s.T(), headerMd, serverHeaderMdKey, "server response headers must contain server data")
assert.Len(s.T(), trailerMd, 1, "server response trailers must contain server data")
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *ProxyHappySuite) TestPingStream_FullDuplexWorks() {
// Check that the header arrives before all entries.
headerMd, err := stream.Header()
require.NoError(s.T(), err, "PingStream headers should not error.")
assert.Len(s.T(), headerMd, 1, "PingStream response headers user contain metadata")
assert.Contains(s.T(), headerMd, serverHeaderMdKey, "PingStream response headers user contain metadata")
}
assert.EqualValues(s.T(), i, resp.Counter, "ping roundtrip must succeed with the correct id")
}
Expand Down

0 comments on commit d5b35f6

Please sign in to comment.