Skip to content

Commit d4bf100

Browse files
committed
separate watcher struct
1 parent 0d031aa commit d4bf100

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

xds/internal/xdsclient/tests/lds_watchers_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ func (lw *listenerWatcher) OnResourceDoesNotExist(onDone xdsresource.OnDoneFunc)
102102
onDone()
103103
}
104104

105+
type listenerWatcherMultiple struct {
106+
updateCh *testutils.Channel
107+
}
108+
109+
func newListenerWatcherMultiple(size int) *listenerWatcherMultiple {
110+
return &listenerWatcherMultiple{updateCh: testutils.NewChannelWithSize(size)}
111+
}
112+
113+
func (cw *listenerWatcherMultiple) OnUpdate(update *xdsresource.ListenerResourceData, onDone xdsresource.OnDoneFunc) {
114+
cw.updateCh.Send(listenerUpdateErrTuple{update: update.Resource})
115+
onDone()
116+
}
117+
118+
func (lw *listenerWatcherMultiple) OnError(err error, onDone xdsresource.OnDoneFunc) {
119+
lw.updateCh.Send(listenerUpdateErrTuple{err: err})
120+
onDone()
121+
}
122+
123+
func (lw *listenerWatcherMultiple) OnResourceDoesNotExist(onDone xdsresource.OnDoneFunc) {
124+
lw.updateCh.Send(listenerUpdateErrTuple{err: xdsresource.NewErrorf(xdsresource.ErrorTypeResourceNotFound, "Listener not found in received response")})
125+
onDone()
126+
}
127+
105128
// badListenerResource returns a listener resource for the given name which does
106129
// not contain the `RouteSpecifier` field in the HTTPConnectionManager, and
107130
// hence is expected to be NACKed by the client.
@@ -1032,7 +1055,7 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10321055

10331056
// Register another watch for the same resource. This should get the update
10341057
// and error from the cache.
1035-
lw2 := newListenerWatcherWithSize(2)
1058+
lw2 := newListenerWatcherMultiple(2)
10361059
ldsCancel2 := xdsresource.WatchListener(client, ldsName, lw2)
10371060
defer ldsCancel2()
10381061
if err := verifyListenerUpdate(ctx, lw2.updateCh, wantUpdate); err != nil {
@@ -1046,6 +1069,15 @@ func (s) TestLDSWatch_ResourceCaching_NACKError(t *testing.T) {
10461069
if gotErr == nil || !strings.Contains(gotErr.Error(), wantListenerNACKErr) {
10471070
t.Fatalf("update received with error: %v, want %q", gotErr, wantListenerNACKErr)
10481071
}
1072+
// No request should get sent out as part of this watch.
1073+
sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout)
1074+
defer sCancel()
1075+
select {
1076+
case <-sCtx.Done():
1077+
case <-secondRequestReceived.Done():
1078+
t.Fatal("xdsClient sent out request instead of using update from cache")
1079+
default:
1080+
}
10491081
}
10501082

10511083
// TestLDSWatch_PartialValid covers the case where a response from the

0 commit comments

Comments
 (0)