@@ -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,16 +208,21 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
196208
197209 // Watch for the listener on the above management server.
198210 xdsresource .WatchListener (client , listenerResourceName , noopListenerWatcher {})
199-
200- // Close the listener and ensure that the ADS stream breaks. This should
201- // cause a server failure count to emit eventually.
202- l .Close ()
211+ // Verify that an ADS stream is opened and an LDS request with the above
212+ // resource name is sent.
203213 select {
214+ case <- streamOpened :
204215 case <- ctx .Done ():
205- t .Fatal ("Timeout when waiting for ADS stream to close" )
206- default :
216+ t .Fatal ("Timeout when waiting for ADS stream to open" )
207217 }
208218
219+ // Close the listener and ensure that the ADS stream breaks. This should
220+ // cause a server failure count to emit eventually.
221+ lis .Stop ()
222+
223+ // Restart to prevent the attempt to create a new ADS stream after back off.
224+ lis .Restart ()
225+
209226 mdWant := stats.MetricsData {
210227 Handle : xdsClientServerFailureMetric .Descriptor (),
211228 IntIncr : 1 ,
@@ -294,10 +311,8 @@ func (s) TestServerFailureMetrics_AfterResponseRecv(t *testing.T) {
294311 // Close the listener and ensure that the ADS stream breaks. This should
295312 // cause a server failure count to emit eventually.
296313 lis .Stop ()
297- select {
298- case <- ctx .Done ():
299- t .Fatal ("Timeout when waiting for ADS stream to close" )
300- default :
314+ if ctx .Err () != nil {
315+ t .Fatalf ("Timeout when waiting for ADS stream to close" )
301316 }
302317 // Restart to prevent the attempt to create a new ADS stream after back off.
303318 lis .Restart ()
0 commit comments