From 56c3b1df0dd8744fe6c301de2d0372d2be697a69 Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Tue, 24 Oct 2023 16:06:00 -0400 Subject: [PATCH] test: Enable XdsTest to run without the test HTTP server This required fixing a couple issues in XdsTestServer: (1) Initialize Libevent before creating the Dispatcher. If we don't do this, and we start the XdsTestServer without starting the Http2TestServer, the LibeventScheduler fails the Libevent::Global::initialized() assert. (2) Add a Thread::SkipAsserts before calling the YAML to Bootstrap parsing. The YAML utilities make some non-relevant asserts on being on the main thread, which aren't applicable when calling the YAML utilities from JNI and tests. To remove the need for the Http2TestServer, we remove the endpoints from the dynamic cluster returned in the test xDS response. This allows us to test the essential xDS behavior without depending on an endpoint for cluster initialization. Signed-off-by: Ali Beyad --- mobile/test/common/integration/BUILD | 1 + mobile/test/common/integration/xds_test_server.cc | 13 +++++++++---- mobile/test/common/jni/test_jni_interface.cc | 2 ++ mobile/test/kotlin/integration/XdsTest.kt | 13 +------------ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mobile/test/common/integration/BUILD b/mobile/test/common/integration/BUILD index 052a73a748e9..6c2905013611 100644 --- a/mobile/test/common/integration/BUILD +++ b/mobile/test/common/integration/BUILD @@ -188,6 +188,7 @@ envoy_cc_test_library( repository = "@envoy", deps = [ ":base_client_integration_test_lib", + "@envoy//source/common/event:libevent_lib", "@envoy//source/common/grpc:google_grpc_creds_lib", "@envoy//source/exe:process_wide_lib", "@envoy//test/integration:autonomous_upstream_lib", diff --git a/mobile/test/common/integration/xds_test_server.cc b/mobile/test/common/integration/xds_test_server.cc index 35f7887edffe..1c61391af0b3 100644 --- a/mobile/test/common/integration/xds_test_server.cc +++ b/mobile/test/common/integration/xds_test_server.cc @@ -2,6 +2,7 @@ #include +#include "source/common/event/libevent.h" #include "source/common/grpc/google_grpc_creds_impl.h" #include "source/extensions/config_subscription/grpc/grpc_collection_subscription_factory.h" #include "source/extensions/config_subscription/grpc/grpc_mux_impl.h" @@ -17,10 +18,14 @@ namespace Envoy { XdsTestServer::XdsTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), version_(Network::Address::IpVersion::v4), - mock_buffer_factory_(new NiceMock), - dispatcher_(api_->allocateDispatcher("test_thread", - Buffer::WatermarkFactoryPtr{mock_buffer_factory_})), - upstream_config_(time_system_) { + mock_buffer_factory_(new NiceMock), upstream_config_(time_system_) { + if (!Envoy::Event::Libevent::Global::initialized()) { + // Required by the Dispatcher. + Envoy::Event::Libevent::Global::initialize(); + } + dispatcher_ = + api_->allocateDispatcher("test_thread", Buffer::WatermarkFactoryPtr{mock_buffer_factory_}); + ON_CALL(*mock_buffer_factory_, createBuffer_(_, _, _)) .WillByDefault(Invoke([](std::function below_low, std::function above_high, std::function above_overflow) -> Buffer::Instance* { diff --git a/mobile/test/common/jni/test_jni_interface.cc b/mobile/test/common/jni/test_jni_interface.cc index 61dc7801bd2e..0ffd910c78a2 100644 --- a/mobile/test/common/jni/test_jni_interface.cc +++ b/mobile/test/common/jni/test_jni_interface.cc @@ -73,6 +73,8 @@ Java_io_envoyproxy_envoymobile_engine_testing_TestJni_nativeSendDiscoveryRespons jstring yaml) { jni_log("[XTS]", "sending DiscoveryResponse from the xDS server"); const char* yaml_chars = env->GetStringUTFChars(yaml, /* isCopy= */ nullptr); + // The yaml utilities have non-relevant thread asserts. + Envoy::Thread::SkipAsserts skip; envoy::service::discovery::v3::DiscoveryResponse response; Envoy::TestUtility::loadFromYaml(yaml_chars, response); sendDiscoveryResponse(response); diff --git a/mobile/test/kotlin/integration/XdsTest.kt b/mobile/test/kotlin/integration/XdsTest.kt index 6994a5f15b5e..ebc3a11ebfd8 100644 --- a/mobile/test/kotlin/integration/XdsTest.kt +++ b/mobile/test/kotlin/integration/XdsTest.kt @@ -28,7 +28,6 @@ class XdsTest { @Before fun setUp() { - TestJni.startHttp2TestServer() TestJni.initXdsTestServer() val latch = CountDownLatch(1) engine = @@ -50,7 +49,6 @@ class XdsTest { @After fun tearDown() { engine.terminate() - TestJni.shutdownTestServer() TestJni.shutdownXdsTestServer() } @@ -66,15 +64,6 @@ class XdsTest { name: my_cluster type: STATIC connect_timeout: 5s - load_assignment: - cluster_name: xds_cluster - endpoints: - - lb_endpoints: - - endpoint: - address: - socket_address: - address: ${TestJni.getServerHost()} - port_value: ${TestJni.getServerPort()} typed_extension_protocol_options: envoy.extensions.upstreams.http.v3.HttpProtocolOptions: "@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions @@ -86,7 +75,7 @@ class XdsTest { """ .trimIndent() TestJni.sendDiscoveryResponse(cdsResponse) - // There are now 3 clusters: base, base_cluster, and xds_cluster. + // There are now 3 clusters: base, base_cluster, and my_cluster. engine.waitForStatGe("cluster_manager.cluster_added", 3) } }