Skip to content

Commit fdc2ec2

Browse files
authored
xdsclient: deflake TestADS_ResourcesAreRequestedAfterStreamRestart (#7720)
1 parent 4115c21 commit fdc2ec2

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

xds/internal/xdsclient/tests/ads_stream_backoff_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,16 @@ func (s) TestADS_ResourceRequestedBeforeStreamCreation(t *testing.T) {
434434
func waitForResourceNames(ctx context.Context, t *testing.T, namesCh chan []string, wantNames []string) error {
435435
t.Helper()
436436

437-
for ; ctx.Err() == nil; <-time.After(defaultTestShortTimeout) {
437+
var lastRequestedNames []string
438+
for ; ; <-time.After(defaultTestShortTimeout) {
438439
select {
439440
case <-ctx.Done():
441+
return fmt.Errorf("timeout waiting for resources %v to be requested from the management server. Last requested resources: %v", wantNames, lastRequestedNames)
440442
case gotNames := <-namesCh:
441443
if cmp.Equal(gotNames, wantNames, cmpopts.EquateEmpty(), cmpopts.SortSlices(func(s1, s2 string) bool { return s1 < s2 })) {
442444
return nil
443445
}
444-
t.Logf("Received resource names %v, want %v", gotNames, wantNames)
446+
lastRequestedNames = gotNames
445447
}
446448
}
447-
return fmt.Errorf("timeout waiting for resource to be requested from the management server")
448449
}

xds/internal/xdsclient/tests/ads_stream_restart_test.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,24 @@ func (s) TestADS_ResourcesAreRequestedAfterStreamRestart(t *testing.T) {
5858
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
5959
Listener: lis,
6060
OnStreamRequest: func(_ int64, req *v3discoverypb.DiscoveryRequest) error {
61+
t.Logf("Received request for resources: %v of type %s", req.GetResourceNames(), req.GetTypeUrl())
62+
63+
// Drain the resource name channels before writing to them to ensure
64+
// that the most recently requested names are made available to the
65+
// test.
6166
switch req.GetTypeUrl() {
6267
case version.V3ClusterURL:
6368
select {
64-
case cdsResourcesCh <- req.GetResourceNames():
69+
case <-cdsResourcesCh:
6570
default:
6671
}
72+
cdsResourcesCh <- req.GetResourceNames()
6773
case version.V3ListenerURL:
68-
t.Logf("Received LDS request for resources: %v", req.GetResourceNames())
6974
select {
70-
case ldsResourcesCh <- req.GetResourceNames():
75+
case <-ldsResourcesCh:
7176
default:
7277
}
78+
ldsResourcesCh <- req.GetResourceNames()
7379
}
7480
return nil
7581
},
@@ -130,6 +136,17 @@ func (s) TestADS_ResourcesAreRequestedAfterStreamRestart(t *testing.T) {
130136
t.Fatal(err)
131137
}
132138

139+
// Verify the update received by the watcher.
140+
wantListenerUpdate := listenerUpdateErrTuple{
141+
update: xdsresource.ListenerUpdate{
142+
RouteConfigName: routeConfigName,
143+
HTTPFilters: []xdsresource.HTTPFilter{{Name: "router"}},
144+
},
145+
}
146+
if err := verifyListenerUpdate(ctx, lw.updateCh, wantListenerUpdate); err != nil {
147+
t.Fatal(err)
148+
}
149+
133150
// Cancel the watch for the above listener resource, and verify that an LDS
134151
// request with no resource names is sent.
135152
ldsCancel()
@@ -171,6 +188,11 @@ func (s) TestADS_ResourcesAreRequestedAfterStreamRestart(t *testing.T) {
171188
}
172189
defer ldsCancel()
173190

191+
// Verify the update received by the watcher.
192+
if err := verifyListenerUpdate(ctx, lw.updateCh, wantListenerUpdate); err != nil {
193+
t.Fatal(err)
194+
}
195+
174196
// Create a cluster resource on the management server, in addition to the
175197
// existing listener resource.
176198
const clusterName = "cluster"
@@ -192,6 +214,17 @@ func (s) TestADS_ResourcesAreRequestedAfterStreamRestart(t *testing.T) {
192214
t.Fatal(err)
193215
}
194216

217+
// Verify the update received by the watcher.
218+
wantClusterUpdate := clusterUpdateErrTuple{
219+
update: xdsresource.ClusterUpdate{
220+
ClusterName: clusterName,
221+
EDSServiceName: clusterName,
222+
},
223+
}
224+
if err := verifyClusterUpdate(ctx, cw.updateCh, wantClusterUpdate); err != nil {
225+
t.Fatal(err)
226+
}
227+
195228
// Cancel the watch for the above cluster resource, and verify that a CDS
196229
// request with no resource names is sent.
197230
cdsCancel()

0 commit comments

Comments
 (0)