diff --git a/test/integration/ads_integration_test.cc b/test/integration/ads_integration_test.cc index e2f7294b9ee3a..39f735cb9938f 100644 --- a/test/integration/ads_integration_test.cc +++ b/test/integration/ads_integration_test.cc @@ -644,7 +644,7 @@ TEST_P(AdsIntegrationTest, XdsBatching) { static_resources->add_listeners()->MergeFrom(buildListener("rds_listener2", "route_config2")); }); - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createXdsConnection(); ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_)); xds_stream_->startGrpcStream(); diff --git a/test/integration/header_integration_test.cc b/test/integration/header_integration_test.cc index 40c0672504c8a..cc59e444488ac 100644 --- a/test/integration/header_integration_test.cc +++ b/test/integration/header_integration_test.cc @@ -338,7 +338,7 @@ class HeaderIntegrationTest void initialize() override { if (use_eds_) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { AssertionResult result = fake_upstreams_[1]->waitForHttpConnection(*dispatcher_, eds_connection_); RELEASE_ASSERT(result, result.message()); diff --git a/test/integration/integration.cc b/test/integration/integration.cc index 6147978f30887..5b8de6e6495a9 100644 --- a/test/integration/integration.cc +++ b/test/integration/integration.cc @@ -368,9 +368,9 @@ void BaseIntegrationTest::registerTestServerPorts(const std::vector void BaseIntegrationTest::createGeneratedApiTestServer(const std::string& bootstrap_path, const std::vector& port_names) { - test_server_ = IntegrationTestServer::create(bootstrap_path, version_, - pre_worker_start_test_steps_, deterministic_, - timeSystem(), *api_, defer_listener_finalization_); + test_server_ = IntegrationTestServer::create(bootstrap_path, version_, on_server_init_function_, + deterministic_, timeSystem(), *api_, + defer_listener_finalization_); if (config_helper_.bootstrap().static_resources().listeners_size() > 0 && !defer_listener_finalization_) { // Wait for listeners to be created before invoking registerTestServerPorts() below, as that @@ -424,9 +424,9 @@ void BaseIntegrationTest::sendRawHttpAndWaitForResponse(int port, const char* ra IntegrationTestServerPtr BaseIntegrationTest::createIntegrationTestServer(const std::string& bootstrap_path, - std::function pre_worker_start_test_steps, + std::function on_server_init_function, Event::TestTimeSystem& time_system) { - return IntegrationTestServer::create(bootstrap_path, version_, pre_worker_start_test_steps, + return IntegrationTestServer::create(bootstrap_path, version_, on_server_init_function, deterministic_, time_system, *api_, defer_listener_finalization_); } diff --git a/test/integration/integration.h b/test/integration/integration.h index 15a77c66d0b67..85cf2acaf168a 100644 --- a/test/integration/integration.h +++ b/test/integration/integration.h @@ -229,7 +229,7 @@ class BaseIntegrationTest : Logger::Loggable { // Will not return until that server is listening. virtual IntegrationTestServerPtr createIntegrationTestServer(const std::string& bootstrap_path, - std::function pre_worker_start_steps, + std::function on_server_init_function, Event::TestTimeSystem& time_system); bool initialized() const { return initialized_; } @@ -238,8 +238,10 @@ class BaseIntegrationTest : Logger::Loggable { Network::Address::IpVersion version_; // The config for envoy start-up. ConfigHelper config_helper_; - // Steps that should be done prior to the workers starting. E.g., xDS pre-init. - std::function pre_worker_start_test_steps_; + + // Steps that should be done in parallel with the envoy server starting. E.g., xDS + // pre-init, control plane synchronization needed for server start. + std::function on_server_init_function_; std::vector> fake_upstreams_; // Target number of upstreams. diff --git a/test/integration/sds_dynamic_integration_test.cc b/test/integration/sds_dynamic_integration_test.cc index e1d026a10defa..e8df32127a617 100644 --- a/test/integration/sds_dynamic_integration_test.cc +++ b/test/integration/sds_dynamic_integration_test.cc @@ -199,7 +199,7 @@ INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, SdsDynamicDownstreamIntegrationTe // A test that SDS server send a good server secret for a static listener. // The first ssl request should be OK. TEST_P(SdsDynamicDownstreamIntegrationTest, BasicSuccess) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getServerSecret()); }; @@ -215,7 +215,7 @@ TEST_P(SdsDynamicDownstreamIntegrationTest, BasicSuccess) { // The first ssl request should fail at connecting. // then SDS send a good server secret, the second request should be OK. TEST_P(SdsDynamicDownstreamIntegrationTest, WrongSecretFirst) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getWrongSecret(server_cert_)); }; @@ -296,7 +296,7 @@ INSTANTIATE_TEST_SUITE_P(IpVersionsClientType, SdsDynamicDownstreamCertValidatio // A test that SDS server send a good certificate validation context for a static listener. // The first ssl request should be OK. TEST_P(SdsDynamicDownstreamCertValidationContextTest, BasicSuccess) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getCvcSecret()); }; @@ -313,7 +313,7 @@ TEST_P(SdsDynamicDownstreamCertValidationContextTest, BasicSuccess) { // The first ssl request should be OK. TEST_P(SdsDynamicDownstreamCertValidationContextTest, CombinedCertValidationContextSuccess) { enableCombinedValidationContext(true); - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getCvcSecretWithOnlyTrustedCa()); }; @@ -375,7 +375,7 @@ INSTANTIATE_TEST_SUITE_P(IpVersions, SdsDynamicUpstreamIntegrationTest, // To test a static cluster with sds. SDS send a good client secret first. // The first request should work. TEST_P(SdsDynamicUpstreamIntegrationTest, BasicSuccess) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getClientSecret()); }; @@ -400,7 +400,7 @@ TEST_P(SdsDynamicUpstreamIntegrationTest, BasicSuccess) { // The first request should fail with 503, then SDS sends a good client secret, // the second request should work. TEST_P(SdsDynamicUpstreamIntegrationTest, WrongSecretFirst) { - pre_worker_start_test_steps_ = [this]() { + on_server_init_function_ = [this]() { createSdsStream(*(fake_upstreams_[1])); sendSdsResponse(getWrongSecret(client_cert_)); }; diff --git a/test/integration/server.cc b/test/integration/server.cc index 4fa5551d9fa0d..ad6581f1ee0a3 100644 --- a/test/integration/server.cc +++ b/test/integration/server.cc @@ -45,11 +45,11 @@ OptionsImpl createTestOptionsImpl(const std::string& config_path, const std::str IntegrationTestServerPtr IntegrationTestServer::create( const std::string& config_path, const Network::Address::IpVersion version, - std::function pre_worker_start_test_steps, bool deterministic, + std::function on_server_init_function, bool deterministic, Event::TestTimeSystem& time_system, Api::Api& api, bool defer_listener_finalization) { IntegrationTestServerPtr server{ std::make_unique(time_system, api, config_path)}; - server->start(version, pre_worker_start_test_steps, deterministic, defer_listener_finalization); + server->start(version, on_server_init_function, deterministic, defer_listener_finalization); return server; } @@ -64,16 +64,20 @@ void IntegrationTestServer::waitUntilListenersReady() { } void IntegrationTestServer::start(const Network::Address::IpVersion version, - std::function pre_worker_start_test_steps, - bool deterministic, bool defer_listener_finalization) { + std::function on_server_init_function, bool deterministic, + bool defer_listener_finalization) { ENVOY_LOG(info, "starting integration test server"); ASSERT(!thread_); thread_ = api_.threadFactory().createThread( [version, deterministic, this]() -> void { threadRoutine(version, deterministic); }); // If any steps need to be done prior to workers starting, do them now. E.g., xDS pre-init. - if (pre_worker_start_test_steps != nullptr) { - pre_worker_start_test_steps(); + // Note that there is no synchronization guaranteeing this happens either + // before workers starting or after server start. Any needed synchronization must occur in the + // routines. These steps are executed at this point in the code to allow server initialization to + // be dependent on them (e.g. control plane peers). + if (on_server_init_function != nullptr) { + on_server_init_function(); } // Wait for the server to be created and the number of initial listeners to wait for to be set. diff --git a/test/integration/server.h b/test/integration/server.h index ca03050c9b97d..3652119081244 100644 --- a/test/integration/server.h +++ b/test/integration/server.h @@ -174,7 +174,7 @@ class IntegrationTestServer : public Logger::Loggable, public: static IntegrationTestServerPtr create(const std::string& config_path, const Network::Address::IpVersion version, - std::function pre_worker_start_test_steps, + std::function on_server_init_function, bool deterministic, Event::TestTimeSystem& time_system, Api::Api& api, bool defer_listener_finalization = false); // Note that the derived class is responsible for tearing down the server in its @@ -191,7 +191,7 @@ class IntegrationTestServer : public Logger::Loggable, on_worker_listener_removed_cb_ = on_worker_listener_removed; } void start(const Network::Address::IpVersion version, - std::function pre_worker_start_test_steps, bool deterministic, + std::function on_server_init_function, bool deterministic, bool defer_listener_finalization); void waitForCounterGe(const std::string& name, uint64_t value) override {