@@ -895,8 +895,8 @@ func (s) TestLDSWatch_ResourceRemoved(t *testing.T) {
895
895
}
896
896
897
897
// TestLDSWatch_NACKError covers the case where an update from the management
898
- // server is NACK'ed by the xdsclient. The test verifies that the error is
899
- // propagated to the existing watcher. After NACK, If a new watcher registers
898
+ // server is NACKed by the xdsclient. The test verifies that the error is
899
+ // propagated to the existing watcher. After NACK, if a new watcher registers
900
900
// for the resource, error is propagated to the new watcher as well.
901
901
func (s ) TestLDSWatch_NACKError (t * testing.T ) {
902
902
mgmtServer := e2e .StartManagementServer (t , e2e.ManagementServerOptions {})
@@ -937,11 +937,11 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
937
937
// Verify that the expected error is propagated to the watcher.
938
938
u , err := lw .updateCh .Receive (ctx )
939
939
if err != nil {
940
- t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
940
+ t .Fatalf ("Timeout when waiting for a listener resource from the management server: %v" , err )
941
941
}
942
942
gotErr := u .(listenerUpdateErrTuple ).err
943
943
if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
944
- t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
944
+ t .Fatalf ("Update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
945
945
}
946
946
947
947
// Verify that the expected error is propagated to the new watcher as well.
@@ -950,11 +950,11 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
950
950
defer ldsCancel2 ()
951
951
u , err = lw2 .updateCh .Receive (ctx )
952
952
if err != nil {
953
- t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
953
+ t .Fatalf ("Timeout when waiting for a listener resource from the management server: %v" , err )
954
954
}
955
955
gotErr = u .(listenerUpdateErrTuple ).err
956
956
if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
957
- t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
957
+ t .Fatalf ("Update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
958
958
}
959
959
}
960
960
@@ -963,18 +963,31 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
963
963
// good update as well as latest NACK error. The test verifies that new watcher
964
964
// receives both good update and error without a new resource request being
965
965
// sent to the management server.
966
- func (s ) TestLDSWatch_ResourceCaching_NACKError (t * testing.T ) {
966
+ func TestLDSWatch_ResourceCaching_NACKError (t * testing.T ) {
967
+ firstRequestReceived := false
968
+ firstAckReceived := grpcsync .NewEvent ()
969
+ secondAckReceived := grpcsync .NewEvent ()
967
970
secondRequestReceived := grpcsync .NewEvent ()
968
971
969
972
mgmtServer := e2e .StartManagementServer (t , e2e.ManagementServerOptions {
970
973
OnStreamRequest : func (id int64 , req * v3discoverypb.DiscoveryRequest ) error {
971
- // If the version is "2", it means that a second request has been
972
- // received (after an initial request and ack). The client should
973
- // not send a second request if the resource is already cached.
974
- if req .GetVersionInfo () == "2" {
975
- secondRequestReceived .Fire ()
974
+ // The first request has an empty version string.
975
+ if ! firstRequestReceived && req .GetVersionInfo () == "" {
976
+ firstRequestReceived = true
976
977
return nil
977
978
}
979
+ // The first ack has a non-empty version string.
980
+ if ! firstAckReceived .HasFired () && req .GetVersionInfo () != "" {
981
+ firstAckReceived .Fire ()
982
+ return nil
983
+ }
984
+ // The second ack has a non-empty version string.
985
+ if ! secondAckReceived .HasFired () && req .GetVersionInfo () != "" {
986
+ secondAckReceived .Fire ()
987
+ return nil
988
+ }
989
+ // Any requests after the first request and two acks, are not expected.
990
+ secondRequestReceived .Fire ()
978
991
return nil
979
992
},
980
993
})
@@ -997,6 +1010,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
997
1010
lw1 := newListenerWatcher ()
998
1011
ldsCancel1 := xdsresource .WatchListener (client , ldsName , lw1 )
999
1012
defer ldsCancel1 ()
1013
+
1000
1014
// Configure the management server to return a single listener
1001
1015
// resource, corresponding to the one we registered a watch for.
1002
1016
resources := e2e.UpdateOptions {
@@ -1009,6 +1023,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1009
1023
if err := mgmtServer .Update (ctx , resources ); err != nil {
1010
1024
t .Fatalf ("Failed to update management server with resources: %v, err: %v" , resources , err )
1011
1025
}
1026
+
1012
1027
// Verify the contents of the received update.
1013
1028
wantUpdate := listenerUpdateErrTuple {
1014
1029
update : xdsresource.ListenerUpdate {
@@ -1030,14 +1045,15 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1030
1045
if err := mgmtServer .Update (ctx , resources ); err != nil {
1031
1046
t .Fatalf ("Failed to update management server with resources: %v, err: %v" , resources , err )
1032
1047
}
1048
+
1033
1049
// Verify that the expected error is propagated to the existing watcher.
1034
1050
u , err := lw1 .updateCh .Receive (ctx )
1035
1051
if err != nil {
1036
1052
t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
1037
1053
}
1038
1054
gotErr := u .(listenerUpdateErrTuple ).err
1039
1055
if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
1040
- t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1056
+ t .Fatalf ("Update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1041
1057
}
1042
1058
1043
1059
// Register another watch for the same resource. This should get the update
@@ -1050,11 +1066,11 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1050
1066
}
1051
1067
u , err = lw2 .updateCh .Receive (ctx )
1052
1068
if err != nil {
1053
- t .Fatalf ("timeout when waiting for a listener resource from the management server: %v" , err )
1069
+ t .Fatalf ("Timeout when waiting for a listener resource from the management server: %v" , err )
1054
1070
}
1055
1071
gotErr = u .(listenerUpdateErrTuple ).err
1056
1072
if gotErr == nil || ! strings .Contains (gotErr .Error (), wantListenerNACKErr ) {
1057
- t .Fatalf ("update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1073
+ t .Fatalf ("Update received with error: %v, want %q" , gotErr , wantListenerNACKErr )
1058
1074
}
1059
1075
// No request should get sent out as part of this watch.
1060
1076
sCtx , sCancel := context .WithTimeout (ctx , defaultTestShortTimeout )
@@ -1069,7 +1085,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
1069
1085
1070
1086
// TestLDSWatch_PartialValid covers the case where a response from the
1071
1087
// management server contains both valid and invalid resources and is expected
1072
- // to be NACK'ed by the xdsclient. The test verifies that watchers corresponding
1088
+ // to be NACKed by the xdsclient. The test verifies that watchers corresponding
1073
1089
// to the valid resource receive the update, while watchers corresponding to the
1074
1090
// invalid resource receive an error.
1075
1091
func (s ) TestLDSWatch_PartialValid (t * testing.T ) {
0 commit comments