@@ -90,6 +90,33 @@ func (cw *listenerWatcher) OnResourceDoesNotExist(onDone xdsresource.OnDoneFunc)
90
90
onDone ()
91
91
}
92
92
93
+ type listenerWatcherMultiple struct {
94
+ updateCh * testutils.Channel
95
+ }
96
+
97
+ func newListenerWatcherMultiple () * listenerWatcherMultiple {
98
+ return & listenerWatcherMultiple {updateCh : testutils .NewChannelWithSize (2 )}
99
+ }
100
+
101
+ func (cw * listenerWatcherMultiple ) OnUpdate (update * xdsresource.ListenerResourceData , onDone xdsresource.OnDoneFunc ) {
102
+ cw .updateCh .Send (listenerUpdateErrTuple {update : update .Resource })
103
+ onDone ()
104
+ }
105
+
106
+ func (cw * listenerWatcherMultiple ) OnError (err error , onDone xdsresource.OnDoneFunc ) {
107
+ // When used with a go-control-plane management server that continuously
108
+ // resends resources which are NACKed by the xDS client, using a `Replace()`
109
+ // here and in OnResourceDoesNotExist() simplifies tests which will have
110
+ // access to the most recently received error.
111
+ cw .updateCh .Send (listenerUpdateErrTuple {err : err })
112
+ onDone ()
113
+ }
114
+
115
+ func (cw * listenerWatcherMultiple ) OnResourceDoesNotExist (onDone xdsresource.OnDoneFunc ) {
116
+ cw .updateCh .Send (listenerUpdateErrTuple {err : xdsresource .NewErrorf (xdsresource .ErrorTypeResourceNotFound , "Listener not found in received response" )})
117
+ onDone ()
118
+ }
119
+
93
120
// badListenerResource returns a listener resource for the given name which does
94
121
// not contain the `RouteSpecifier` field in the HTTPConnectionManager, and
95
122
// hence is expected to be NACKed by the client.
@@ -547,7 +574,7 @@ func (s) TestLDSWatch_ThreeWatchesForDifferentResourceNames(t *testing.T) {
547
574
// a resource which is already present in the cache. The test verifies that the
548
575
// watch callback is invoked with the contents from the cache, instead of a
549
576
// request being sent to the management server.
550
- func ( s ) TestLDSWatch_ResourceCaching (t * testing.T ) {
577
+ func TestLDSWatch_ResourceCaching (t * testing.T ) {
551
578
firstRequestReceived := false
552
579
firstAckReceived := grpcsync .NewEvent ()
553
580
secondRequestReceived := grpcsync .NewEvent ()
@@ -926,7 +953,7 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
926
953
// good update and latest NACK error. The test verifies that new watcher
927
954
// receives both good update and error without request being sent to the
928
955
// management server.
929
- func ( s ) TestLDSWatch_ResourceCaching_NACKError (t * testing.T ) {
956
+ func TestLDSWatch_ResourceCaching_NACKError (t * testing.T ) {
930
957
firstRequestReceived := false
931
958
firstAckReceived := grpcsync .NewEvent ()
932
959
secondRequestReceived := grpcsync .NewEvent ()
@@ -943,6 +970,13 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
943
970
firstAckReceived .Fire ()
944
971
return nil
945
972
}
973
+ // If the request version remains "1" while the nonce keeps
974
+ // increasing, it indicates the client is repeatedly NACKing
975
+ // updates from the server but not sending any new resource
976
+ // request.
977
+ if req .GetVersionInfo () == "1" {
978
+ return nil
979
+ }
946
980
// Any requests after the first request and ack, are not expected.
947
981
secondRequestReceived .Fire ()
948
982
return nil
@@ -1018,21 +1052,12 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1018
1052
1019
1053
// Register another watch for the same resource. This should get the update
1020
1054
// and error from the cache.
1021
- lw2 := newListenerWatcher ()
1055
+ lw2 := newListenerWatcherMultiple ()
1022
1056
ldsCancel2 := xdsresource .WatchListener (client , ldsName , lw2 )
1023
1057
defer ldsCancel2 ()
1024
1058
if err := verifyListenerUpdate (ctx , lw2 .updateCh , wantUpdate ); err != nil {
1025
1059
t .Fatal (err )
1026
1060
}
1027
- u , err = lw2 .updateCh .Receive (ctx )
1028
- if err != nil {
1029
- t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
1030
- }
1031
- gotErr = u .(listenerUpdateErrTuple ).err
1032
- if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
1033
- t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1034
- }
1035
-
1036
1061
// No request should get sent out as part of this watch.
1037
1062
sCtx , sCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
1038
1063
defer sCancel ()
@@ -1041,6 +1066,14 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1041
1066
case <- secondRequestReceived .Done ():
1042
1067
t .Fatal ("xdsClient sent out request instead of using update from cache" )
1043
1068
}
1069
+ u , err = lw2 .updateCh .Receive (ctx )
1070
+ if err != nil {
1071
+ t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
1072
+ }
1073
+ gotErr = u .(listenerUpdateErrTuple ).err
1074
+ if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
1075
+ t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1076
+ }
1044
1077
}
1045
1078
1046
1079
// TestLDSWatch_PartialValid covers the case where a response from the
0 commit comments