@@ -46,7 +46,7 @@ type assertingService struct {
4646
4747func (s * assertingService ) PingEmpty (ctx context.Context , _ * pb.Empty ) (* pb.PingResponse , error ) {
4848 // Check that this call has client's metadata.
49- md , ok := metadata .FromContext (ctx )
49+ md , ok := metadata .FromIncomingContext (ctx )
5050 assert .True (s .t , ok , "PingEmpty call must have metadata in context" )
5151 _ , ok = md [clientMdKey ]
5252 assert .True (s .t , ok , "PingEmpty call must have clients's custom headers in metadata" )
@@ -116,7 +116,7 @@ func (s *ProxyHappySuite) ctx() context.Context {
116116}
117117
118118func (s * ProxyHappySuite ) TestPingEmptyCarriesClientMetadata () {
119- ctx := metadata .NewContext (s .ctx (), metadata .Pairs (clientMdKey , "true" ))
119+ ctx := metadata .NewOutgoingContext (s .ctx (), metadata .Pairs (clientMdKey , "true" ))
120120 out , err := s .testClient .PingEmpty (ctx , & pb.Empty {})
121121 require .NoError (s .T (), err , "PingEmpty should succeed without errors" )
122122 require .Equal (s .T (), & pb.PingResponse {Value : pingDefaultValue , Counter : 42 }, out )
@@ -148,7 +148,7 @@ func (s *ProxyHappySuite) TestPingErrorPropagatesAppError() {
148148
149149func (s * ProxyHappySuite ) TestDirectorErrorIsPropagated () {
150150 // See SetupSuite where the StreamDirector has a special case.
151- ctx := metadata .NewContext (s .ctx (), metadata .Pairs (rejectingMdKey , "true" ))
151+ ctx := metadata .NewOutgoingContext (s .ctx (), metadata .Pairs (rejectingMdKey , "true" ))
152152 _ , err := s .testClient .Ping (ctx , & pb.PingRequest {Value : "foo" })
153153 require .Error (s .T (), err , "Director should reject this RPC" )
154154 assert .Equal (s .T (), codes .PermissionDenied , grpc .Code (err ))
@@ -204,14 +204,17 @@ func (s *ProxyHappySuite) SetupSuite() {
204204 // Setup of the proxy's Director.
205205 s .serverClientConn , err = grpc .Dial (s .serverListener .Addr ().String (), grpc .WithInsecure (), grpc .WithCodec (proxy .Codec ()))
206206 require .NoError (s .T (), err , "must not error on deferred client Dial" )
207- director := func (ctx context.Context , fullName string ) (* grpc.ClientConn , error ) {
208- md , ok := metadata .FromContext (ctx )
207+ director := func (ctx context.Context , fullName string ) (context. Context , * grpc.ClientConn , error ) {
208+ md , ok := metadata .FromIncomingContext (ctx )
209209 if ok {
210210 if _ , exists := md [rejectingMdKey ]; exists {
211- return nil , grpc .Errorf (codes .PermissionDenied , "testing rejection" )
211+ return ctx , nil , grpc .Errorf (codes .PermissionDenied , "testing rejection" )
212212 }
213213 }
214- return s .serverClientConn , nil
214+ // Explicitly copy the metadata, otherwise the tests will fail.
215+ outCtx , _ := context .WithCancel (ctx )
216+ outCtx = metadata .NewOutgoingContext (outCtx , md .Copy ())
217+ return outCtx , s .serverClientConn , nil
215218 }
216219 s .proxy = grpc .NewServer (
217220 grpc .CustomCodec (proxy .Codec ()),
0 commit comments