Skip to content

Commit 10b5065

Browse files
committed
Revert "Merge pull request grpc#22952 from grpc/revert-22922-sequential_conn"
This reverts commit 30ad47d, reversing changes made to ad7c94c.
1 parent c649738 commit 10b5065

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

test/core/surface/sequential_connectivity_test.cc

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
*
1717
*/
1818

19+
#include <vector>
20+
1921
#include <grpc/grpc.h>
2022
#include <grpc/grpc_security.h>
23+
#include <grpc/impl/codegen/grpc_types.h>
2124
#include <grpc/support/alloc.h>
2225
#include <grpc/support/log.h>
2326

@@ -36,16 +39,12 @@
3639
typedef struct test_fixture {
3740
const char* name;
3841
void (*add_server_port)(grpc_server* server, const char* addr);
39-
grpc_channel* (*create_channel)(const char* addr);
42+
// Have the creds here so all the channels will share the same one to enabled
43+
// subchannel sharing if needed.
44+
grpc_channel_credentials* creds;
4045
} test_fixture;
4146

42-
/* TODO(yashykt): When our macos testing infrastructure becomes good enough, we
43-
* wouldn't need to reduce the number of connections on MacOS */
44-
#ifdef __APPLE__
4547
#define NUM_CONNECTIONS 100
46-
#else
47-
#define NUM_CONNECTIONS 1000
48-
#endif /* __APPLE__ */
4948

5049
typedef struct {
5150
grpc_server* server;
@@ -61,8 +60,31 @@ static void server_thread_func(void* args) {
6160
GPR_ASSERT(ev.success == true);
6261
}
6362

64-
static void run_test(const test_fixture* fixture) {
65-
gpr_log(GPR_INFO, "TEST: %s", fixture->name);
63+
static grpc_channel* create_test_channel(const char* addr,
64+
grpc_channel_credentials* creds,
65+
bool share_subchannel) {
66+
grpc_channel* channel = nullptr;
67+
std::vector<grpc_arg> args;
68+
args.push_back(grpc_channel_arg_integer_create(
69+
const_cast<char*>(GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL),
70+
!share_subchannel));
71+
if (creds != nullptr) {
72+
args.push_back(grpc_channel_arg_string_create(
73+
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
74+
const_cast<char*>("foo.test.google.fr")));
75+
}
76+
grpc_channel_args channel_args = {args.size(), args.data()};
77+
if (creds != nullptr) {
78+
channel = grpc_secure_channel_create(creds, addr, &channel_args, nullptr);
79+
} else {
80+
channel = grpc_insecure_channel_create(addr, &channel_args, nullptr);
81+
}
82+
return channel;
83+
}
84+
85+
static void run_test(const test_fixture* fixture, bool share_subchannel) {
86+
gpr_log(GPR_INFO, "TEST: %s sharing subchannel: %d", fixture->name,
87+
share_subchannel);
6688

6789
grpc_init();
6890

@@ -83,7 +105,8 @@ static void run_test(const test_fixture* fixture) {
83105
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
84106
grpc_channel* channels[NUM_CONNECTIONS];
85107
for (size_t i = 0; i < NUM_CONNECTIONS; i++) {
86-
channels[i] = fixture->create_channel(addr.c_str());
108+
channels[i] =
109+
create_test_channel(addr.c_str(), fixture->creds, share_subchannel);
87110

88111
gpr_timespec connect_deadline = grpc_timeout_seconds_to_deadline(30);
89112
grpc_connectivity_state state;
@@ -132,16 +155,6 @@ static void insecure_test_add_port(grpc_server* server, const char* addr) {
132155
grpc_server_add_insecure_http2_port(server, addr);
133156
}
134157

135-
static grpc_channel* insecure_test_create_channel(const char* addr) {
136-
return grpc_insecure_channel_create(addr, nullptr, nullptr);
137-
}
138-
139-
static const test_fixture insecure_test = {
140-
"insecure",
141-
insecure_test_add_port,
142-
insecure_test_create_channel,
143-
};
144-
145158
static void secure_test_add_port(grpc_server* server, const char* addr) {
146159
grpc_slice cert_slice, key_slice;
147160
GPR_ASSERT(GRPC_LOG_IF_ERROR(
@@ -161,7 +174,18 @@ static void secure_test_add_port(grpc_server* server, const char* addr) {
161174
grpc_server_credentials_release(ssl_creds);
162175
}
163176

164-
static grpc_channel* secure_test_create_channel(const char* addr) {
177+
int main(int argc, char** argv) {
178+
grpc::testing::TestEnvironment env(argc, argv);
179+
180+
const test_fixture insecure_test = {
181+
"insecure",
182+
insecure_test_add_port,
183+
nullptr,
184+
};
185+
186+
run_test(&insecure_test, /*share_subchannel=*/true);
187+
run_test(&insecure_test, /*share_subchannel=*/false);
188+
165189
grpc_slice ca_slice;
166190
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
167191
grpc_load_file(CA_CERT_PATH, 1, &ca_slice)));
@@ -170,31 +194,12 @@ static grpc_channel* secure_test_create_channel(const char* addr) {
170194
grpc_channel_credentials* ssl_creds =
171195
grpc_ssl_credentials_create(test_root_cert, nullptr, nullptr, nullptr);
172196
grpc_slice_unref(ca_slice);
173-
grpc_arg ssl_name_override = {
174-
GRPC_ARG_STRING,
175-
const_cast<char*>(GRPC_SSL_TARGET_NAME_OVERRIDE_ARG),
176-
{const_cast<char*>("foo.test.google.fr")}};
177-
grpc_channel_args* new_client_args =
178-
grpc_channel_args_copy_and_add(nullptr, &ssl_name_override, 1);
179-
grpc_channel* channel =
180-
grpc_secure_channel_create(ssl_creds, addr, new_client_args, nullptr);
181-
{
182-
grpc_core::ExecCtx exec_ctx;
183-
grpc_channel_args_destroy(new_client_args);
184-
}
197+
const test_fixture secure_test = {
198+
"secure",
199+
secure_test_add_port,
200+
ssl_creds,
201+
};
202+
run_test(&secure_test, /*share_subchannel=*/true);
203+
run_test(&secure_test, /*share_subchannel=*/false);
185204
grpc_channel_credentials_release(ssl_creds);
186-
return channel;
187-
}
188-
189-
static const test_fixture secure_test = {
190-
"secure",
191-
secure_test_add_port,
192-
secure_test_create_channel,
193-
};
194-
195-
int main(int argc, char** argv) {
196-
grpc::testing::TestEnvironment env(argc, argv);
197-
198-
run_test(&insecure_test);
199-
run_test(&secure_test);
200205
}

0 commit comments

Comments
 (0)