Skip to content

Commit df88c19

Browse files
committed
address nits, verify caching without version number
1 parent 8ed2a3a commit df88c19

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

xds/internal/xdsclient/authority.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,10 @@ func (a *authority) watchResource(rType xdsresource.Type, resourceName string, w
644644
}
645645
// If last update was NACK'd, notify the new watcher of error
646646
// immediately as well.
647-
if state.md.Status == xdsresource.ServiceStatusNACKed && state.md.ErrState != nil {
647+
if state.md.Status == xdsresource.ServiceStatusNACKed {
648+
if a.logger.V(2) {
649+
a.logger.Infof("Resource type %q with resource name %q was NACKed: %s", rType.TypeName(), resourceName, state.cache.ToJSON())
650+
}
648651
a.watcherCallbackSerializer.TrySchedule(func(context.Context) { watcher.OnError(state.md.ErrState.Err, func() {}) })
649652
}
650653
cleanup = a.unwatchResource(rType, resourceName, watcher)

xds/internal/xdsclient/tests/lds_watchers_test.go

+32-16
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ func (s) TestLDSWatch_ResourceRemoved(t *testing.T) {
895895
}
896896

897897
// 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
900900
// for the resource, error is propagated to the new watcher as well.
901901
func (s) TestLDSWatch_NACKError(t *testing.T) {
902902
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{})
@@ -937,11 +937,11 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
937937
// Verify that the expected error is propagated to the watcher.
938938
u, err := lw.updateCh.Receive(ctx)
939939
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)
941941
}
942942
gotErr := u.(listenerUpdateErrTuple).err
943943
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)
945945
}
946946

947947
// Verify that the expected error is propagated to the new watcher as well.
@@ -950,11 +950,11 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
950950
defer ldsCancel2()
951951
u, err = lw2.updateCh.Receive(ctx)
952952
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)
954954
}
955955
gotErr = u.(listenerUpdateErrTuple).err
956956
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)
958958
}
959959
}
960960

@@ -963,18 +963,31 @@ func (s) TestLDSWatch_NACKError(t *testing.T) {
963963
// good update as well as latest NACK error. The test verifies that new watcher
964964
// receives both good update and error without a new resource request being
965965
// 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()
967970
secondRequestReceived := grpcsync.NewEvent()
968971

969972
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
970973
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
976977
return nil
977978
}
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()
978991
return nil
979992
},
980993
})
@@ -997,6 +1010,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
9971010
lw1 := newListenerWatcher()
9981011
ldsCancel1 := xdsresource.WatchListener(client, ldsName, lw1)
9991012
defer ldsCancel1()
1013+
10001014
// Configure the management server to return a single listener
10011015
// resource, corresponding to the one we registered a watch for.
10021016
resources := e2e.UpdateOptions{
@@ -1009,6 +1023,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10091023
if err := mgmtServer.Update(ctx, resources); err != nil {
10101024
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
10111025
}
1026+
10121027
// Verify the contents of the received update.
10131028
wantUpdate := listenerUpdateErrTuple{
10141029
update: xdsresource.ListenerUpdate{
@@ -1030,14 +1045,15 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10301045
if err := mgmtServer.Update(ctx, resources); err != nil {
10311046
t.Fatalf("Failed to update management server with resources: %v, err: %v", resources, err)
10321047
}
1048+
10331049
// Verify that the expected error is propagated to the existing watcher.
10341050
u, err := lw1.updateCh.Receive(ctx)
10351051
if err != nil {
10361052
t.Fatalf("timeout when waiting for a listener resource from the management server: %v", err)
10371053
}
10381054
gotErr := u.(listenerUpdateErrTuple).err
10391055
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)
10411057
}
10421058

10431059
// Register another watch for the same resource. This should get the update
@@ -1050,11 +1066,11 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10501066
}
10511067
u, err = lw2.updateCh.Receive(ctx)
10521068
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)
10541070
}
10551071
gotErr = u.(listenerUpdateErrTuple).err
10561072
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)
10581074
}
10591075
// No request should get sent out as part of this watch.
10601076
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
@@ -1069,7 +1085,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10691085

10701086
// TestLDSWatch_PartialValid covers the case where a response from the
10711087
// 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
10731089
// to the valid resource receive the update, while watchers corresponding to the
10741090
// invalid resource receive an error.
10751091
func (s) TestLDSWatch_PartialValid(t *testing.T) {

0 commit comments

Comments
 (0)