@@ -199,7 +199,7 @@ func TestRelayErrorsOnGetPeer(t *testing.T) {
199199 }
200200
201201 for _ , tt := range tests {
202- f := func (relay.CallFrame , relay. Conn ) (string , error ) {
202+ f := func (relay.CallFrame , * Connection ) (string , error ) {
203203 return tt .returnPeer , tt .returnErr
204204 }
205205
@@ -502,8 +502,8 @@ func TestRelayMakeOutgoingCall(t *testing.T) {
502502func TestRelayConnection (t * testing.T ) {
503503 var errTest = errors .New ("test" )
504504 var wantHostPort string
505- getHost := func (call relay.CallFrame , conn relay. Conn ) (string , error ) {
506- assert .Equal (t , wantHostPort , conn .RemoteHostPort () , "Unexpected RemoteHostPort" )
505+ getHost := func (call relay.CallFrame , conn * Connection ) (string , error ) {
506+ assert .Equal (t , wantHostPort , conn .RemotePeerInfo (). HostPort , "Unexpected RemoteHostPort" )
507507 return "" , errTest
508508 }
509509
@@ -519,6 +519,35 @@ func TestRelayConnection(t *testing.T) {
519519 err := testutils .CallEcho (client , ts .HostPort (), ts .ServiceName (), nil )
520520 require .Error (t , err , "Expected CallEcho to fail" )
521521 assert .Contains (t , err .Error (), errTest .Error (), "Unexpected error" )
522+
523+ // Verify that the relay has not closed any connections.
524+ assert .Equal (t , 1 , ts .Relay ().IntrospectNumConnections (), "Relay should maintain client connection" )
525+ })
526+ }
527+
528+ func TestRelayConnectionClosed (t * testing.T ) {
529+ protocolErr := NewSystemError (ErrCodeProtocol , "invalid service name" )
530+ getHost := func (call relay.CallFrame , conn * Connection ) (string , error ) {
531+ return "" , protocolErr
532+ }
533+
534+ opts := testutils .NewOpts ().
535+ SetRelayOnly ().
536+ SetRelayHost (relaytest .HostFunc (getHost ))
537+ testutils .WithTestServer (t , opts , func (ts * testutils.TestServer ) {
538+ // The client receives a protocol error which causes the following logs.
539+ opts := testutils .NewOpts ().
540+ AddLogFilter ("Peer reported protocol error" , 1 ).
541+ AddLogFilter ("Connection error" , 1 )
542+ client := ts .NewClient (opts )
543+
544+ err := testutils .CallEcho (client , ts .HostPort (), ts .ServiceName (), nil )
545+ assert .Equal (t , protocolErr , err , "Unexpected error on call" )
546+
547+ closedAll := testutils .WaitFor (time .Second , func () bool {
548+ return ts .Relay ().IntrospectNumConnections () == 0
549+ })
550+ assert .True (t , closedAll , "Relay should close client connection" )
522551 })
523552}
524553
@@ -577,7 +606,7 @@ func TestRelayRejectsDuringClose(t *testing.T) {
577606}
578607
579608func TestRelayRateLimitDrop (t * testing.T ) {
580- getHost := func (call relay.CallFrame , conn relay. Conn ) (string , error ) {
609+ getHost := func (call relay.CallFrame , _ * Connection ) (string , error ) {
581610 return "" , relay.RateLimitDropError {}
582611 }
583612
@@ -691,7 +720,7 @@ func TestRelayThroughSeparateRelay(t *testing.T) {
691720 SetRelayOnly ()
692721 testutils .WithTestServer (t , opts , func (ts * testutils.TestServer ) {
693722 serverHP := ts .Server ().PeerInfo ().HostPort
694- dummyFactory := func (relay.CallFrame , relay. Conn ) (string , error ) {
723+ dummyFactory := func (relay.CallFrame , * Connection ) (string , error ) {
695724 panic ("should not get invoked" )
696725 }
697726 relay2Opts := testutils .NewOpts ().SetRelayHost (relaytest .HostFunc (dummyFactory ))
0 commit comments