@@ -46,10 +46,10 @@ import (
46
46
_ "google.golang.org/grpc/xds/internal/xdsclient/controller/version/v3" // Register the v3 xDS API client.
47
47
)
48
48
49
- func overrideFedEnvVar (t * testing.T ) func () {
49
+ func overrideFedEnvVar (t * testing.T ) {
50
50
oldFed := envconfig .XDSFederation
51
51
envconfig .XDSFederation = true
52
- return func () { envconfig .XDSFederation = oldFed }
52
+ t . Cleanup ( func () { envconfig .XDSFederation = oldFed })
53
53
}
54
54
55
55
type s struct {
@@ -148,7 +148,7 @@ func verifyListenerUpdate(ctx context.Context, updateCh *testutils.Channel, want
148
148
//
149
149
// The test is run for old and new style names.
150
150
func (s ) TestLDSWatch (t * testing.T ) {
151
- defer overrideFedEnvVar (t )( )
151
+ overrideFedEnvVar (t )
152
152
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
153
153
defer cleanup ()
154
154
@@ -268,7 +268,7 @@ func (s) TestLDSWatch(t *testing.T) {
268
268
//
269
269
// The test is run for old and new style names.
270
270
func (s ) TestLDSWatch_TwoWatchesForSameResourceName (t * testing.T ) {
271
- defer overrideFedEnvVar (t )( )
271
+ overrideFedEnvVar (t )
272
272
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
273
273
defer cleanup ()
274
274
@@ -402,7 +402,7 @@ func (s) TestLDSWatch_TwoWatchesForSameResourceName(t *testing.T) {
402
402
//
403
403
// The test is run with both old and new style names.
404
404
func (s ) TestLDSWatch_ThreeWatchesForDifferentResourceNames (t * testing.T ) {
405
- defer overrideFedEnvVar (t )( )
405
+ overrideFedEnvVar (t )
406
406
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
407
407
defer cleanup ()
408
408
@@ -474,7 +474,7 @@ func (s) TestLDSWatch_ThreeWatchesForDifferentResourceNames(t *testing.T) {
474
474
// watch callback is invoked with the contents from the cache, instead of a
475
475
// request being sent to the management server.
476
476
func (s ) TestLDSWatch_ResourceCaching (t * testing.T ) {
477
- defer overrideFedEnvVar (t )( )
477
+ overrideFedEnvVar (t )
478
478
firstRequestReceived := false
479
479
firstAckReceived := grpcsync .NewEvent ()
480
480
secondRequestReceived := grpcsync .NewEvent ()
@@ -574,7 +574,7 @@ func (s) TestLDSWatch_ResourceCaching(t *testing.T) {
574
574
//
575
575
// The test is run with both old and new style names.
576
576
func (s ) TestLDSWatch_ResourceRemoved (t * testing.T ) {
577
- defer overrideFedEnvVar (t )( )
577
+ overrideFedEnvVar (t )
578
578
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
579
579
defer cleanup ()
580
580
@@ -682,7 +682,7 @@ func (s) TestLDSWatch_ResourceRemoved(t *testing.T) {
682
682
// server is NACK'ed by the xdsclient. The test verifies that the error is
683
683
// propagated to the watcher.
684
684
func (s ) TestLDSWatch_NACKError (t * testing.T ) {
685
- defer overrideFedEnvVar (t )( )
685
+ overrideFedEnvVar (t )
686
686
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
687
687
defer cleanup ()
688
688
@@ -695,9 +695,11 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
695
695
696
696
// Register a watch for a listener resource and have the watch
697
697
// callback push the received update on to a channel.
698
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
699
+ defer cancel ()
698
700
updateCh := testutils .NewChannel ()
699
701
ldsCancel := client .WatchListener (ldsName , func (u xdsresource.ListenerUpdate , err error ) {
700
- updateCh .Send ( xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
702
+ updateCh .SendContext ( ctx , xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
701
703
})
702
704
defer ldsCancel ()
703
705
@@ -708,8 +710,6 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
708
710
Listeners : []* v3listenerpb.Listener {badListenerResource (ldsName )},
709
711
SkipValidation : true ,
710
712
}
711
- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
712
- defer cancel ()
713
713
if err := mgmtServer .Update (ctx , resources ); err != nil {
714
714
t .Fatalf ("Failed to update management server with resources: %v, err: %v" , resources , err )
715
715
}
@@ -731,7 +731,7 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
731
731
// to the valid resource receive the update, while watchers corresponding to the
732
732
// invalid resource receive an error.
733
733
func (s ) TestLDSWatch_PartialValid (t * testing.T ) {
734
- defer overrideFedEnvVar (t )( )
734
+ overrideFedEnvVar (t )
735
735
mgmtServer , nodeID , bootstrapContents , _ , cleanup := e2e .SetupManagementServer (t , nil )
736
736
defer cleanup ()
737
737
@@ -745,15 +745,18 @@ func (s) TestLDSWatch_PartialValid(t *testing.T) {
745
745
// Register two watches for listener resources. The first watch is expected
746
746
// to receive an error because the received resource is NACKed. The second
747
747
// watch is expected to get a good update.
748
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
749
+ defer cancel ()
750
+ badResourceName := ldsName
748
751
updateCh1 := testutils .NewChannel ()
749
- ldsCancel1 := client .WatchListener (ldsName , func (u xdsresource.ListenerUpdate , err error ) {
750
- updateCh1 .Send ( xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
752
+ ldsCancel1 := client .WatchListener (badResourceName , func (u xdsresource.ListenerUpdate , err error ) {
753
+ updateCh1 .SendContext ( ctx , xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
751
754
})
752
755
defer ldsCancel1 ()
753
- resourceName2 := ldsNameNewStyle
756
+ goodResourceName := ldsNameNewStyle
754
757
updateCh2 := testutils .NewChannel ()
755
- ldsCancel2 := client .WatchListener (resourceName2 , func (u xdsresource.ListenerUpdate , err error ) {
756
- updateCh2 .Send ( xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
758
+ ldsCancel2 := client .WatchListener (goodResourceName , func (u xdsresource.ListenerUpdate , err error ) {
759
+ updateCh2 .SendContext ( ctx , xdsresource.ListenerUpdateErrTuple {Update : u , Err : err })
757
760
})
758
761
defer ldsCancel2 ()
759
762
@@ -762,13 +765,11 @@ func (s) TestLDSWatch_PartialValid(t *testing.T) {
762
765
resources := e2e.UpdateOptions {
763
766
NodeID : nodeID ,
764
767
Listeners : []* v3listenerpb.Listener {
765
- badListenerResource (ldsName ),
766
- e2e .DefaultClientListener (resourceName2 , rdsName ),
768
+ badListenerResource (badResourceName ),
769
+ e2e .DefaultClientListener (goodResourceName , rdsName ),
767
770
},
768
771
SkipValidation : true ,
769
772
}
770
- ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
771
- defer cancel ()
772
773
if err := mgmtServer .Update (ctx , resources ); err != nil {
773
774
t .Fatalf ("Failed to update management server with resources: %v, err: %v" , resources , err )
774
775
}
0 commit comments