From 10b50653eec9f7a1e60958e1f1f9816f1396610c Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 15 May 2020 13:00:56 -0700 Subject: [PATCH 1/2] Revert "Merge pull request #22952 from grpc/revert-22922-sequential_conn" This reverts commit 30ad47d81992f833b6d0dcfa084a10e0b45013be, reversing changes made to ad7c94c944dffba152d4253422488f749677c2ae. --- .../surface/sequential_connectivity_test.cc | 99 ++++++++++--------- 1 file changed, 52 insertions(+), 47 deletions(-) diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index ed20017d708..d0ed9a76ec0 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -16,8 +16,11 @@ * */ +#include + #include #include +#include #include #include @@ -36,16 +39,12 @@ typedef struct test_fixture { const char* name; void (*add_server_port)(grpc_server* server, const char* addr); - grpc_channel* (*create_channel)(const char* addr); + // Have the creds here so all the channels will share the same one to enabled + // subchannel sharing if needed. + grpc_channel_credentials* creds; } test_fixture; -/* TODO(yashykt): When our macos testing infrastructure becomes good enough, we - * wouldn't need to reduce the number of connections on MacOS */ -#ifdef __APPLE__ #define NUM_CONNECTIONS 100 -#else -#define NUM_CONNECTIONS 1000 -#endif /* __APPLE__ */ typedef struct { grpc_server* server; @@ -61,8 +60,31 @@ static void server_thread_func(void* args) { GPR_ASSERT(ev.success == true); } -static void run_test(const test_fixture* fixture) { - gpr_log(GPR_INFO, "TEST: %s", fixture->name); +static grpc_channel* create_test_channel(const char* addr, + grpc_channel_credentials* creds, + bool share_subchannel) { + grpc_channel* channel = nullptr; + std::vector args; + args.push_back(grpc_channel_arg_integer_create( + const_cast(GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL), + !share_subchannel)); + if (creds != nullptr) { + args.push_back(grpc_channel_arg_string_create( + const_cast(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), + const_cast("foo.test.google.fr"))); + } + grpc_channel_args channel_args = {args.size(), args.data()}; + if (creds != nullptr) { + channel = grpc_secure_channel_create(creds, addr, &channel_args, nullptr); + } else { + channel = grpc_insecure_channel_create(addr, &channel_args, nullptr); + } + return channel; +} + +static void run_test(const test_fixture* fixture, bool share_subchannel) { + gpr_log(GPR_INFO, "TEST: %s sharing subchannel: %d", fixture->name, + share_subchannel); grpc_init(); @@ -83,7 +105,8 @@ static void run_test(const test_fixture* fixture) { grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr); grpc_channel* channels[NUM_CONNECTIONS]; for (size_t i = 0; i < NUM_CONNECTIONS; i++) { - channels[i] = fixture->create_channel(addr.c_str()); + channels[i] = + create_test_channel(addr.c_str(), fixture->creds, share_subchannel); gpr_timespec connect_deadline = grpc_timeout_seconds_to_deadline(30); grpc_connectivity_state state; @@ -132,16 +155,6 @@ static void insecure_test_add_port(grpc_server* server, const char* addr) { grpc_server_add_insecure_http2_port(server, addr); } -static grpc_channel* insecure_test_create_channel(const char* addr) { - return grpc_insecure_channel_create(addr, nullptr, nullptr); -} - -static const test_fixture insecure_test = { - "insecure", - insecure_test_add_port, - insecure_test_create_channel, -}; - static void secure_test_add_port(grpc_server* server, const char* addr) { grpc_slice cert_slice, key_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR( @@ -161,7 +174,18 @@ static void secure_test_add_port(grpc_server* server, const char* addr) { grpc_server_credentials_release(ssl_creds); } -static grpc_channel* secure_test_create_channel(const char* addr) { +int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); + + const test_fixture insecure_test = { + "insecure", + insecure_test_add_port, + nullptr, + }; + + run_test(&insecure_test, /*share_subchannel=*/true); + run_test(&insecure_test, /*share_subchannel=*/false); + grpc_slice ca_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file", grpc_load_file(CA_CERT_PATH, 1, &ca_slice))); @@ -170,31 +194,12 @@ static grpc_channel* secure_test_create_channel(const char* addr) { grpc_channel_credentials* ssl_creds = grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr, nullptr); grpc_slice_unref(ca_slice); - grpc_arg ssl_name_override = { - GRPC_ARG_STRING, - const_cast(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG), - {const_cast("foo.test.google.fr")}}; - grpc_channel_args* new_client_args = - grpc_channel_args_copy_and_add(nullptr, &ssl_name_override, 1); - grpc_channel* channel = - grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr); - { - grpc_core::ExecCtx exec_ctx; - grpc_channel_args_destroy(new_client_args); - } + const test_fixture secure_test = { + "secure", + secure_test_add_port, + ssl_creds, + }; + run_test(&secure_test, /*share_subchannel=*/true); + run_test(&secure_test, /*share_subchannel=*/false); grpc_channel_credentials_release(ssl_creds); - return channel; -} - -static const test_fixture secure_test = { - "secure", - secure_test_add_port, - secure_test_create_channel, -}; - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - - run_test(&insecure_test); - run_test(&secure_test); } From 2b78747d157d53882a921e0eb86515fa8d455d44 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 15 May 2020 13:02:04 -0700 Subject: [PATCH 2/2] Let grpc_init/shutdown cover credentials create/release --- test/core/surface/sequential_connectivity_test.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/core/surface/sequential_connectivity_test.cc b/test/core/surface/sequential_connectivity_test.cc index d0ed9a76ec0..401821f69a4 100644 --- a/test/core/surface/sequential_connectivity_test.cc +++ b/test/core/surface/sequential_connectivity_test.cc @@ -86,8 +86,6 @@ static void run_test(const test_fixture* fixture, bool share_subchannel) { gpr_log(GPR_INFO, "TEST: %s sharing subchannel: %d", fixture->name, share_subchannel); - grpc_init(); - std::string addr = grpc_core::JoinHostPort("localhost", grpc_pick_unused_port_or_die()); @@ -147,8 +145,6 @@ static void run_test(const test_fixture* fixture, bool share_subchannel) { grpc_server_destroy(server); grpc_completion_queue_destroy(server_cq); grpc_completion_queue_destroy(cq); - - grpc_shutdown(); } static void insecure_test_add_port(grpc_server* server, const char* addr) { @@ -176,13 +172,13 @@ static void secure_test_add_port(grpc_server* server, const char* addr) { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); + grpc_init(); const test_fixture insecure_test = { "insecure", insecure_test_add_port, nullptr, }; - run_test(&insecure_test, /*share_subchannel=*/true); run_test(&insecure_test, /*share_subchannel=*/false); @@ -202,4 +198,6 @@ int main(int argc, char** argv) { run_test(&secure_test, /*share_subchannel=*/true); run_test(&secure_test, /*share_subchannel=*/false); grpc_channel_credentials_release(ssl_creds); + + grpc_shutdown(); }