Skip to content

Commit c31cf42

Browse files
committed
xdsclient: fix TestServerFailureMetrics_BeforeResponseRecv test to wait for watch to start before stopping the listener
1 parent 5edab9e commit c31cf42

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

xds/internal/xdsclient/metrics_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,19 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
160160
if err != nil {
161161
t.Fatalf("net.Listen() failed: %v", err)
162162
}
163-
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: l})
163+
lis := testutils.NewRestartableListener(l)
164+
streamOpened := make(chan struct{}, 1)
165+
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
166+
Listener: lis,
167+
OnStreamOpen: func(context.Context, int64, string) error {
168+
select {
169+
case streamOpened <- struct{}{}:
170+
default:
171+
}
172+
return nil
173+
},
174+
})
175+
164176
nodeID := uuid.New().String()
165177

166178
bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{
@@ -196,10 +208,19 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
196208

197209
// Watch for the listener on the above management server.
198210
xdsresource.WatchListener(client, listenerResourceName, noopListenerWatcher{})
211+
// Verify that an ADS stream is opened and an LDS request with the above
212+
// resource name is sent.
213+
select {
214+
case <-streamOpened:
215+
case <-ctx.Done():
216+
t.Fatal("Timeout when waiting for ADS stream to open")
217+
}
218+
// Restart to prevent the attempt to create a new ADS stream after back off.
219+
lis.Restart()
199220

200221
// Close the listener and ensure that the ADS stream breaks. This should
201222
// cause a server failure count to emit eventually.
202-
l.Close()
223+
lis.Stop()
203224
select {
204225
case <-ctx.Done():
205226
t.Fatal("Timeout when waiting for ADS stream to close")

0 commit comments

Comments
 (0)