@@ -523,7 +523,9 @@ func (s) TestCZChannelMetrics(t *testing.T) {
523523 cc := te .clientConn (grpc .WithResolvers (r ))
524524 defer te .tearDown ()
525525 tc := testgrpc .NewTestServiceClient (cc )
526- if _ , err := tc .EmptyCall (context .Background (), & testpb.Empty {}); err != nil {
526+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
527+ defer cancel ()
528+ if _ , err := tc .EmptyCall (ctx , & testpb.Empty {}); err != nil {
527529 t .Fatalf ("TestService/EmptyCall(_, _) = _, %v, want _, <nil>" , err )
528530 }
529531
@@ -540,11 +542,11 @@ func (s) TestCZChannelMetrics(t *testing.T) {
540542 Payload : largePayload ,
541543 }
542544
543- if _ , err := tc .UnaryCall (context . Background () , req ); err == nil || status .Code (err ) != codes .ResourceExhausted {
545+ if _ , err := tc .UnaryCall (ctx , req ); err == nil || status .Code (err ) != codes .ResourceExhausted {
544546 t .Fatalf ("TestService/UnaryCall(_, _) = _, %v, want _, error code: %s" , err , codes .ResourceExhausted )
545547 }
546548
547- stream , err := tc .FullDuplexCall (context . Background () )
549+ stream , err := tc .FullDuplexCall (ctx )
548550 if err != nil {
549551 t .Fatalf ("%v.FullDuplexCall(_) = _, %v, want <nil>" , tc , err )
550552 }
@@ -603,7 +605,9 @@ func (s) TestCZServerMetrics(t *testing.T) {
603605 defer te .tearDown ()
604606 cc := te .clientConn ()
605607 tc := testgrpc .NewTestServiceClient (cc )
606- if _ , err := tc .EmptyCall (context .Background (), & testpb.Empty {}); err != nil {
608+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
609+ defer cancel ()
610+ if _ , err := tc .EmptyCall (ctx , & testpb.Empty {}); err != nil {
607611 t .Fatalf ("TestService/EmptyCall(_, _) = _, %v, want _, <nil>" , err )
608612 }
609613
@@ -619,11 +623,11 @@ func (s) TestCZServerMetrics(t *testing.T) {
619623 ResponseSize : int32 (smallSize ),
620624 Payload : largePayload ,
621625 }
622- if _ , err := tc .UnaryCall (context . Background () , req ); err == nil || status .Code (err ) != codes .ResourceExhausted {
626+ if _ , err := tc .UnaryCall (ctx , req ); err == nil || status .Code (err ) != codes .ResourceExhausted {
623627 t .Fatalf ("TestService/UnaryCall(_, _) = _, %v, want _, error code: %s" , err , codes .ResourceExhausted )
624628 }
625629
626- stream , err := tc .FullDuplexCall (context . Background () )
630+ stream , err := tc .FullDuplexCall (ctx )
627631 if err != nil {
628632 t .Fatalf ("%v.FullDuplexCall(_) = _, %v, want <nil>" , tc , err )
629633 }
@@ -746,7 +750,7 @@ func doServerSideFailedUnaryCall(tc testgrpc.TestServiceClient, t *testing.T) {
746750}
747751
748752func doClientSideInitiatedFailedStream (tc testgrpc.TestServiceClient , t * testing.T ) {
749- ctx , cancel := context .WithCancel (context .Background ())
753+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
750754 stream , err := tc .FullDuplexCall (ctx )
751755 if err != nil {
752756 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
@@ -779,7 +783,9 @@ func doClientSideInitiatedFailedStream(tc testgrpc.TestServiceClient, t *testing
779783
780784// This func is to be used to test client side counting of failed streams.
781785func doServerSideInitiatedFailedStreamWithRSTStream (tc testgrpc.TestServiceClient , t * testing.T , l * listenerWrapper ) {
782- stream , err := tc .FullDuplexCall (context .Background ())
786+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
787+ defer cancel ()
788+ stream , err := tc .FullDuplexCall (ctx )
783789 if err != nil {
784790 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
785791 }
@@ -816,10 +822,10 @@ func doServerSideInitiatedFailedStreamWithRSTStream(tc testgrpc.TestServiceClien
816822}
817823
818824// this func is to be used to test client side counting of failed streams.
819- func doServerSideInitiatedFailedStreamWithGoAway (tc testgrpc.TestServiceClient , t * testing.T , l * listenerWrapper ) {
825+ func doServerSideInitiatedFailedStreamWithGoAway (ctx context. Context , tc testgrpc.TestServiceClient , t * testing.T , l * listenerWrapper ) {
820826 // This call is just to keep the transport from shutting down (socket will be deleted
821827 // in this case, and we will not be able to get metrics).
822- s , err := tc .FullDuplexCall (context . Background () )
828+ s , err := tc .FullDuplexCall (ctx )
823829 if err != nil {
824830 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
825831 }
@@ -834,7 +840,7 @@ func doServerSideInitiatedFailedStreamWithGoAway(tc testgrpc.TestServiceClient,
834840 t .Fatalf ("s.Recv() failed with error: %v" , err )
835841 }
836842
837- s , err = tc .FullDuplexCall (context . Background () )
843+ s , err = tc .FullDuplexCall (ctx )
838844 if err != nil {
839845 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
840846 }
@@ -859,7 +865,7 @@ func doServerSideInitiatedFailedStreamWithGoAway(tc testgrpc.TestServiceClient,
859865}
860866
861867func doIdleCallToInvokeKeepAlive (tc testgrpc.TestServiceClient , t * testing.T ) {
862- ctx , cancel := context .WithCancel (context .Background ())
868+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
863869 _ , err := tc .FullDuplexCall (ctx )
864870 if err != nil {
865871 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
@@ -870,6 +876,9 @@ func doIdleCallToInvokeKeepAlive(tc testgrpc.TestServiceClient, t *testing.T) {
870876}
871877
872878func (s ) TestCZClientSocketMetricsStreamsAndMessagesCount (t * testing.T ) {
879+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
880+ defer cancel ()
881+
873882 czCleanup := channelz .NewChannelzStorageForTesting ()
874883 defer czCleanupWrapper (czCleanup , t )
875884 e := tcpClearRREnv
@@ -951,7 +960,7 @@ func (s) TestCZClientSocketMetricsStreamsAndMessagesCount(t *testing.T) {
951960 t .Fatal (err )
952961 }
953962
954- doServerSideInitiatedFailedStreamWithGoAway (tc , t , rcw )
963+ doServerSideInitiatedFailedStreamWithGoAway (ctx , tc , t , rcw )
955964 if err := verifyResultWithDelay (func () (bool , error ) {
956965 skt := channelz .GetSocket (skID )
957966 sktData := skt .SocketData
@@ -988,7 +997,7 @@ func (s) TestCZClientAndServerSocketMetricsStreamsCountFlowControlRSTStream(t *t
988997 cc , dw := te .clientConnWithConnControl ()
989998 tc := & testServiceClientWrapper {TestServiceClient : testgrpc .NewTestServiceClient (cc )}
990999
991- ctx , cancel := context .WithTimeout (context .Background (), 5 * time . Second )
1000+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
9921001 stream , err := tc .FullDuplexCall (ctx )
9931002 if err != nil {
9941003 t .Fatalf ("TestService/FullDuplexCall(_) = _, %v, want <nil>" , err )
@@ -1534,7 +1543,7 @@ func (s) TestCZSubChannelTraceCreationDeletion(t *testing.T) {
15341543 t .Fatal (err )
15351544 }
15361545
1537- ctx , cancel := context .WithTimeout (context .Background (), 5 * time . Second )
1546+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
15381547 defer cancel ()
15391548 awaitState (ctx , t , te .cc , connectivity .Ready )
15401549 r .UpdateState (resolver.State {Addresses : []resolver.Address {{Addr : "fake address" }}})
@@ -1694,7 +1703,7 @@ func (s) TestCZSubChannelPickedNewAddress(t *testing.T) {
16941703 defer te .tearDown ()
16951704 tc := testgrpc .NewTestServiceClient (cc )
16961705 // make sure the connection is up
1697- ctx , cancel := context .WithTimeout (context .Background (), time . Second )
1706+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
16981707 defer cancel ()
16991708 if _ , err := tc .EmptyCall (ctx , & testpb.Empty {}); err != nil {
17001709 t .Fatalf ("TestService/EmptyCall(_, _) = _, %v, want _, <nil>" , err )
@@ -1707,9 +1716,7 @@ func (s) TestCZSubChannelPickedNewAddress(t *testing.T) {
17071716 defer close (done )
17081717 go func () {
17091718 for {
1710- ctx , cancel := context .WithTimeout (context .Background (), time .Second )
17111719 tc .EmptyCall (ctx , & testpb.Empty {})
1712- cancel ()
17131720 select {
17141721 case <- time .After (10 * time .Millisecond ):
17151722 case <- done :
@@ -1763,7 +1770,7 @@ func (s) TestCZSubChannelConnectivityState(t *testing.T) {
17631770 defer te .tearDown ()
17641771 tc := testgrpc .NewTestServiceClient (cc )
17651772 // make sure the connection is up
1766- ctx , cancel := context .WithTimeout (context .Background (), time . Second )
1773+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
17671774 defer cancel ()
17681775 if _ , err := tc .EmptyCall (ctx , & testpb.Empty {}); err != nil {
17691776 t .Fatalf ("TestService/EmptyCall(_, _) = _, %v, want _, <nil>" , err )
@@ -1862,7 +1869,7 @@ func (s) TestCZChannelConnectivityState(t *testing.T) {
18621869 defer te .tearDown ()
18631870 tc := testgrpc .NewTestServiceClient (cc )
18641871 // make sure the connection is up
1865- ctx , cancel := context .WithTimeout (context .Background (), time . Second )
1872+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
18661873 defer cancel ()
18671874 if _ , err := tc .EmptyCall (ctx , & testpb.Empty {}); err != nil {
18681875 t .Fatalf ("TestService/EmptyCall(_, _) = _, %v, want _, <nil>" , err )
@@ -2010,7 +2017,7 @@ func (s) TestCZTraceOverwriteSubChannelDeletion(t *testing.T) {
20102017 t .Fatal (err )
20112018 }
20122019
2013- ctx , cancel := context .WithTimeout (context .Background (), 5 * time . Second )
2020+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
20142021 defer cancel ()
20152022 awaitState (ctx , t , te .cc , connectivity .Ready )
20162023 r .UpdateState (resolver.State {Addresses : []resolver.Address {{Addr : "fake address" }}})
0 commit comments