@@ -160,7 +160,19 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
160
160
if err != nil {
161
161
t .Fatalf ("net.Listen() failed: %v" , err )
162
162
}
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
+
164
176
nodeID := uuid .New ().String ()
165
177
166
178
bootstrapContents , err := bootstrap .NewContentsForTesting (bootstrap.ConfigOptionsForTesting {
@@ -196,16 +208,21 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
196
208
197
209
// Watch for the listener on the above management server.
198
210
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.
203
213
select {
214
+ case <- streamOpened :
204
215
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" )
207
217
}
208
218
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
+
209
226
mdWant := stats.MetricsData {
210
227
Handle : xdsClientServerFailureMetric .Descriptor (),
211
228
IntIncr : 1 ,
@@ -294,10 +311,8 @@ func (s) TestServerFailureMetrics_AfterResponseRecv(t *testing.T) {
294
311
// Close the listener and ensure that the ADS stream breaks. This should
295
312
// cause a server failure count to emit eventually.
296
313
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" )
301
316
}
302
317
// Restart to prevent the attempt to create a new ADS stream after back off.
303
318
lis .Restart ()
0 commit comments