xdsclient: fix TestServerFailureMetrics_BeforeResponseRecv test to wait for watch to start before stopping the listener (#8217)

This commit is contained in:
Purnesh Dixit 2025-04-03 09:45:55 +05:30 committed by GitHub
parent 5edab9e554
commit 57a2605e35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 11 deletions

View File

@ -160,7 +160,19 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("net.Listen() failed: %v", err) t.Fatalf("net.Listen() failed: %v", err)
} }
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{Listener: l}) lis := testutils.NewRestartableListener(l)
streamOpened := make(chan struct{}, 1)
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{
Listener: lis,
OnStreamOpen: func(context.Context, int64, string) error {
select {
case streamOpened <- struct{}{}:
default:
}
return nil
},
})
nodeID := uuid.New().String() nodeID := uuid.New().String()
bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{ bootstrapContents, err := bootstrap.NewContentsForTesting(bootstrap.ConfigOptionsForTesting{
@ -196,15 +208,20 @@ func (s) TestServerFailureMetrics_BeforeResponseRecv(t *testing.T) {
// Watch for the listener on the above management server. // Watch for the listener on the above management server.
xdsresource.WatchListener(client, listenerResourceName, noopListenerWatcher{}) xdsresource.WatchListener(client, listenerResourceName, noopListenerWatcher{})
// Verify that an ADS stream is opened and an LDS request with the above
// resource name is sent.
select {
case <-streamOpened:
case <-ctx.Done():
t.Fatal("Timeout when waiting for ADS stream to open")
}
// Close the listener and ensure that the ADS stream breaks. This should // Close the listener and ensure that the ADS stream breaks. This should
// cause a server failure count to emit eventually. // cause a server failure count to emit eventually.
l.Close() lis.Stop()
select {
case <-ctx.Done(): // Restart to prevent the attempt to create a new ADS stream after back off.
t.Fatal("Timeout when waiting for ADS stream to close") lis.Restart()
default:
}
mdWant := stats.MetricsData{ mdWant := stats.MetricsData{
Handle: xdsClientServerFailureMetric.Descriptor(), Handle: xdsClientServerFailureMetric.Descriptor(),
@ -294,10 +311,8 @@ func (s) TestServerFailureMetrics_AfterResponseRecv(t *testing.T) {
// Close the listener and ensure that the ADS stream breaks. This should // Close the listener and ensure that the ADS stream breaks. This should
// cause a server failure count to emit eventually. // cause a server failure count to emit eventually.
lis.Stop() lis.Stop()
select { if ctx.Err() != nil {
case <-ctx.Done(): t.Fatalf("Timeout when waiting for ADS stream to close")
t.Fatal("Timeout when waiting for ADS stream to close")
default:
} }
// Restart to prevent the attempt to create a new ADS stream after back off. // Restart to prevent the attempt to create a new ADS stream after back off.
lis.Restart() lis.Restart()