Skip to content

Commit

Permalink
test: some test framework improvements to enable multi-envoy tests (#…
Browse files Browse the repository at this point in the history
…19892)

factoring out some utility functions, and fixing up test asserts to be multi-envoy friendly.

Risk Level: low
Testing: in https://github.com/alyssawilk/envoy/tree/multi_envoy
Docs Changes: n/a
Release Notes: n/a
part of envoyproxy/envoy-mobile#2003

Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Feb 15, 2022
1 parent 42cd5bc commit f9002e8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 5 additions & 3 deletions source/common/common/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ struct ThreadIds {
// properly.
void releaseMainThread() {
absl::MutexLock lock(&mutex_);
ASSERT(main_thread_use_count_ > 0);
ASSERT(std::this_thread::get_id() == main_thread_id_);
if (!skipAsserts()) {
ASSERT(main_thread_use_count_ > 0);
ASSERT(std::this_thread::get_id() == main_thread_id_);
}
if (--main_thread_use_count_ == 0) {
// Clearing the thread ID when its use-count goes to zero allows us
// to read the atomic without taking a lock.
Expand All @@ -53,7 +55,7 @@ struct ThreadIds {
// thread matches any previous declarations.
void registerMainThread() {
absl::MutexLock lock(&mutex_);
if (++main_thread_use_count_ > 1) {
if (++main_thread_use_count_ > 1 && !skipAsserts()) {
ASSERT(std::this_thread::get_id() == main_thread_id_);
} else {
main_thread_id_ = std::this_thread::get_id();
Expand Down
33 changes: 19 additions & 14 deletions test/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,23 @@ void ConfigHelper::finalize(const std::vector<uint32_t>& ports) {

applyConfigModifiers();

setPorts(ports);

if (!connect_timeout_set_) {
#ifdef __APPLE__
// Set a high default connect timeout. Under heavy load (and in particular in CI), macOS
// connections can take inordinately long to complete.
setConnectTimeout(std::chrono::seconds(30));
#else
// Set a default connect timeout.
setConnectTimeout(std::chrono::seconds(5));
#endif
}

finalized_ = true;
}

void ConfigHelper::setPorts(const std::vector<uint32_t>& ports, bool override_port_zero) {
uint32_t port_idx = 0;
bool eds_hosts = false;
bool custom_cluster = false;
Expand All @@ -864,7 +881,8 @@ void ConfigHelper::finalize(const std::vector<uint32_t>& ports) {
for (int k = 0; k < locality_lb->lb_endpoints_size(); ++k) {
auto lb_endpoint = locality_lb->mutable_lb_endpoints(k);
if (lb_endpoint->endpoint().address().has_socket_address()) {
if (lb_endpoint->endpoint().address().socket_address().port_value() == 0) {
if (lb_endpoint->endpoint().address().socket_address().port_value() == 0 ||
override_port_zero) {
RELEASE_ASSERT(ports.size() > port_idx, "");
lb_endpoint->mutable_endpoint()
->mutable_address()
Expand All @@ -881,19 +899,6 @@ void ConfigHelper::finalize(const std::vector<uint32_t>& ports) {
}
ASSERT(skip_port_usage_validation_ || port_idx == ports.size() || eds_hosts ||
original_dst_cluster || custom_cluster || bootstrap_.dynamic_resources().has_cds_config());

if (!connect_timeout_set_) {
#ifdef __APPLE__
// Set a high default connect timeout. Under heavy load (and in particular in CI), macOS
// connections can take inordinately long to complete.
setConnectTimeout(std::chrono::seconds(30));
#else
// Set a default connect timeout.
setConnectTimeout(std::chrono::seconds(5));
#endif
}

finalized_ = true;
}

void ConfigHelper::setSourceAddress(const std::string& address_string) {
Expand Down
3 changes: 3 additions & 0 deletions test/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class ConfigHelper {
// order they are stored in |bootstrap_|
void finalize(const std::vector<uint32_t>& ports);

// Called by finalize to set up the ports.
void setPorts(const std::vector<uint32_t>& ports, bool override_port_zero = false);

// Set source_address in the bootstrap bind config.
void setSourceAddress(const std::string& address_string);

Expand Down

0 comments on commit f9002e8

Please sign in to comment.