Repository: envoyproxy/envoy
File: test/integration/ads_integration_test.cc (C++)

Code before:
  // Verify all vhosts across all listeners are correctly configured.
  send_request_and_verify("http0", foo_request_headers);
  send_request_and_verify("http0", bar_request_headers);
  send_request_and_verify("http1", foo_request_headers);
  send_request_and_verify("http1", bar_request_headers);
  send_request_and_verify("http2", foo_request_headers);

  // Verify that removing listener_0 doesn't impact listener_1 that also references
  // route_config_0/foo and route_config_0/bar.
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(Config::TestTypeUrl::get().Listener,
                                                               {}, {}, {"listener_0"}, "1");
  send_request_and_verify("http1", foo_request_headers);
  send_request_and_verify("http1", bar_request_headers);

  // Verify that removing route_config_0/foo makes foo.com unreachable but bar.com is still
  // reachable from listener_1.
  sendDiscoveryResponse<envoy::config::route::v3::VirtualHost>(
      Config::TestTypeUrl::get().VirtualHost, {}, {}, {"route_config_0/foo"}, "1");
  send_request_and_verify("http1", foo_request_headers, true);
  send_request_and_verify("http1", bar_request_headers);

  // Verify that listener_2 is unaffected and continues to work.
  send_request_and_verify("http2", foo_request_headers);
}

// Verifies that when two listeners are using the same VHDS resource and after one of the listeners
// is removed, the other listener continues to receive updates on that VHDS resource.
TEST_P(AdsIntegrationTest, VHDSUpdatesAfterListenerRemoval) {
  if (sotw_or_delta_ != Grpc::SotwOrDelta::Delta &&
      sotw_or_delta_ != Grpc::SotwOrDelta::UnifiedDelta) {
    GTEST_SKIP_("This test is for delta only");
  }
  initialize();

  // Send initial configuration that sets up two listeners with the following vhosts:
  // listener_0 -> route_config_0/foo
  // listener_1 -> route_config_0/foo
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}, true));
  sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TestTypeUrl::get().Cluster, {},
                                                             {buildCluster("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {},
                                      {"cluster_0"}, {}));
  sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
      Config::TestTypeUrl::get().ClusterLoadAssignment, {},
      {buildClusterLoadAssignment("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}));

  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Listener, "", {}, {}, {}));
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
      Config::TestTypeUrl::get().Listener, {},
      {buildListener("listener_0", "route_config_0"),

Review comment (suggestion):
```suggestion
// Verifies that when two listeners are using the same route with VHDS resource and after one of the listeners
```

Code after:
  // Verify all vhosts across all listeners are correctly configured.
  send_request_and_verify("http0", foo_request_headers);
  send_request_and_verify("http0", bar_request_headers);
  send_request_and_verify("http1", foo_request_headers);
  send_request_and_verify("http1", bar_request_headers);
  send_request_and_verify("http2", foo_request_headers);

  // Verify that removing listener_0 doesn't impact listener_1 that also references
  // route_config_0/foo and route_config_0/bar.
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(Config::TestTypeUrl::get().Listener,
                                                               {}, {}, {"listener_0"}, "1");
  send_request_and_verify("http1", foo_request_headers);
  send_request_and_verify("http1", bar_request_headers);

  // Verify that removing route_config_0/foo makes foo.com unreachable but bar.com is still
  // reachable from listener_1.
  sendDiscoveryResponse<envoy::config::route::v3::VirtualHost>(
      Config::TestTypeUrl::get().VirtualHost, {}, {}, {"route_config_0/foo"}, "1");
  send_request_and_verify("http1", foo_request_headers, true);
  send_request_and_verify("http1", bar_request_headers);

  // Verify that listener_2 is unaffected and continues to work.
  send_request_and_verify("http2", foo_request_headers);
}

// Verifies that when two listeners are using the same route with VHDS resource and after one of the
// listeners is removed, the other listener continues to receive updates on that VHDS resource.
TEST_P(AdsIntegrationTest, VHDSUpdatesAfterListenerRemoval) {
  if (sotw_or_delta_ != Grpc::SotwOrDelta::Delta &&
      sotw_or_delta_ != Grpc::SotwOrDelta::UnifiedDelta) {
    GTEST_SKIP_("This test is for delta only");
  }
  initialize();

  // Send initial configuration that sets up two listeners with the following vhosts:
  // listener_0 -> route_config_0/foo
  // listener_1 -> route_config_0/foo
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}, true));
  sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TestTypeUrl::get().Cluster, {},
                                                             {buildCluster("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {},
                                      {"cluster_0"}, {}));
  sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
      Config::TestTypeUrl::get().ClusterLoadAssignment, {},
      {buildClusterLoadAssignment("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}));

  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Listener, "", {}, {}, {}));
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
      Config::TestTypeUrl::get().Listener, {},
      {buildListener("listener_0", "route_config_0"),