diff --git a/test/xds/xds_server_serving_mode_test.go b/test/xds/xds_server_serving_mode_test.go index 03a62ed6c784..118a63394f8b 100644 --- a/test/xds/xds_server_serving_mode_test.go +++ b/test/xds/xds_server_serving_mode_test.go @@ -112,9 +112,18 @@ func (s) TestServerSideXDS_RedundantUpdateSuppression(t *testing.T) { // suppressed, server will recycle client connections. errCh := make(chan error, 1) go func() { - if cc.WaitForStateChange(ctx, connectivity.Ready) { - errCh <- fmt.Errorf("unexpected connectivity state change {%s --> %s} on the client connection", connectivity.Ready, cc.GetState()) - return + prev := connectivity.Ready // We know we are READY since we just did an RPC. + for { + curr := cc.GetState() + if !(curr == connectivity.Ready || curr == connectivity.Idle) { + errCh <- fmt.Errorf("unexpected connectivity state change {%s --> %s} on the client connection", prev, curr) + return + } + if !cc.WaitForStateChange(ctx, curr) { + // Break out of the for loop when the context has been cancelled. + break + } + prev = curr } errCh <- nil }()