Skip to content

Commit

Permalink
test: Enable XdsTest to run without the test HTTP server
Browse files Browse the repository at this point in the history
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 <abeyad@google.com>
  • Loading branch information
abeyad committed Oct 24, 2023
1 parent 48bf974 commit 56c3b1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
1 change: 1 addition & 0 deletions mobile/test/common/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 9 additions & 4 deletions mobile/test/common/integration/xds_test_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <utility>

#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"
Expand All @@ -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<MockBufferFactory>),
dispatcher_(api_->allocateDispatcher("test_thread",
Buffer::WatermarkFactoryPtr{mock_buffer_factory_})),
upstream_config_(time_system_) {
mock_buffer_factory_(new NiceMock<MockBufferFactory>), 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<void()> below_low, std::function<void()> above_high,
std::function<void()> above_overflow) -> Buffer::Instance* {
Expand Down
2 changes: 2 additions & 0 deletions mobile/test/common/jni/test_jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 1 addition & 12 deletions mobile/test/kotlin/integration/XdsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class XdsTest {

@Before
fun setUp() {
TestJni.startHttp2TestServer()
TestJni.initXdsTestServer()
val latch = CountDownLatch(1)
engine =
Expand All @@ -50,7 +49,6 @@ class XdsTest {
@After
fun tearDown() {
engine.terminate()
TestJni.shutdownTestServer()
TestJni.shutdownXdsTestServer()
}

Expand All @@ -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
Expand All @@ -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)
}
}

0 comments on commit 56c3b1d

Please sign in to comment.