@@ -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