@@ -77,16 +77,39 @@ func (cw *listenerWatcher) OnUpdate(update *xdsresource.ListenerResourceData, on
77
77
}
78
78
79
79
func (cw * listenerWatcher ) OnError (err error , onDone xdsresource.OnDoneFunc ) {
80
+ cw .updateCh .Replace (listenerUpdateErrTuple {err : err })
81
+ onDone ()
82
+ }
83
+
84
+ func (cw * listenerWatcher ) OnResourceDoesNotExist (onDone xdsresource.OnDoneFunc ) {
85
+ cw .updateCh .Replace (listenerUpdateErrTuple {err : xdsresource .NewErrorf (xdsresource .ErrorTypeResourceNotFound , "Listener not found in received response" )})
86
+ onDone ()
87
+ }
88
+
89
+ type listenerWatcherMultiple struct {
90
+ updateCh * testutils.Channel
91
+ }
92
+
93
+ func newListenerWatcherMultiple () * listenerWatcherMultiple {
94
+ return & listenerWatcherMultiple {updateCh : testutils .NewChannelWithSize (2 )}
95
+ }
96
+
97
+ func (cw * listenerWatcherMultiple ) OnUpdate (update * xdsresource.ListenerResourceData , onDone xdsresource.OnDoneFunc ) {
98
+ cw .updateCh .Send (listenerUpdateErrTuple {update : update .Resource })
99
+ onDone ()
100
+ }
101
+
102
+ func (cw * listenerWatcherMultiple ) OnError (err error , onDone xdsresource.OnDoneFunc ) {
80
103
// When used with a go-control-plane management server that continuously
81
104
// resends resources which are NACKed by the xDS client, using a `Replace()`
82
105
// here and in OnResourceDoesNotExist() simplifies tests which will have
83
106
// access to the most recently received error.
84
- cw .updateCh .Replace (listenerUpdateErrTuple {err : err })
107
+ cw .updateCh .Send (listenerUpdateErrTuple {err : err })
85
108
onDone ()
86
109
}
87
110
88
- func (cw * listenerWatcher ) OnResourceDoesNotExist (onDone xdsresource.OnDoneFunc ) {
89
- cw .updateCh .Replace (listenerUpdateErrTuple {err : xdsresource .NewErrorf (xdsresource .ErrorTypeResourceNotFound , "Listener not found in received response" )})
111
+ func (cw * listenerWatcherMultiple ) OnResourceDoesNotExist (onDone xdsresource.OnDoneFunc ) {
112
+ cw .updateCh .Send (listenerUpdateErrTuple {err : xdsresource .NewErrorf (xdsresource .ErrorTypeResourceNotFound , "Listener not found in received response" )})
90
113
onDone ()
91
114
}
92
115
@@ -923,9 +946,9 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
923
946
924
947
// TestLDSWatch_ResourceCaching_WithNACKError covers the case where a watch is
925
948
// registered for a resource which is already present in the cache with an old
926
- // good update and latest NACK error. The test verifies that new watcher
927
- // receives both good update and error without request being sent to the
928
- // management server.
949
+ // good update as well latest NACK error. The test verifies that new watcher
950
+ // receives both good update and error without a new resource request being
951
+ // sent to the management server.
929
952
func (s ) TestLDSWatch_ResourceCaching_NACKError (t * testing.T ) {
930
953
firstRequestReceived := false
931
954
firstAckReceived := grpcsync .NewEvent ()
@@ -943,6 +966,13 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
943
966
firstAckReceived .Fire ()
944
967
return nil
945
968
}
969
+ // If the request version remains "1" while the nonce keeps
970
+ // increasing, it indicates the client is repeatedly NACKing
971
+ // updates from the server but not sending any new resource
972
+ // request.
973
+ if req .GetVersionInfo () == "1" {
974
+ return nil
975
+ }
946
976
// Any requests after the first request and ack, are not expected.
947
977
secondRequestReceived .Fire ()
948
978
return nil
@@ -1018,21 +1048,12 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1018
1048
1019
1049
// Register another watch for the same resource. This should get the update
1020
1050
// and error from the cache.
1021
- lw2 := newListenerWatcher ()
1051
+ lw2 := newListenerWatcherMultiple ()
1022
1052
ldsCancel2 := xdsresource .WatchListener (client , ldsName , lw2 )
1023
1053
defer ldsCancel2 ()
1024
1054
if err := verifyListenerUpdate (ctx , lw2 .updateCh , wantUpdate ); err != nil {
1025
1055
t .Fatal (err )
1026
1056
}
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
1057
// No request should get sent out as part of this watch.
1037
1058
sCtx , sCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
1038
1059
defer sCancel ()
@@ -1041,6 +1062,14 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1041
1062
case <- secondRequestReceived .Done ():
1042
1063
t .Fatal ("xdsClient sent out request instead of using update from cache" )
1043
1064
}
1065
+ u , err = lw2 .updateCh .Receive (ctx )
1066
+ if err != nil {
1067
+ t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
1068
+ }
1069
+ gotErr = u .(listenerUpdateErrTuple ).err
1070
+ if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
1071
+ t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1072
+ }
1044
1073
}
1045
1074
1046
1075
// TestLDSWatch_PartialValid covers the case where a response from the
0 commit comments