aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2017-09-25 12:38:17 -0700
committerGravatar Muxi Yan <mxyan@google.com>2017-09-25 12:38:17 -0700
commit1c285b98122ef8fe31aa3325a4c10f5b05107ca8 (patch)
treef811ca6879a76bb526a7af7a35e987780d1bcba8 /test
parentd4bb9bddd6cd1bfa4829deee9c3163c6065dafcb (diff)
parent008a173a7e2ba1d5c0933aa7a77395945ba2024d (diff)
Merge remote-tracking branch 'upstream/master' into fix-stream-compression-config-interface
Diffstat (limited to 'test')
-rw-r--r--test/core/client_channel/lb_policies_test.c2
-rw-r--r--test/core/compression/algorithm_test.c2
-rw-r--r--test/core/compression/compression_test.c2
-rw-r--r--test/core/compression/message_compress_test.c2
-rw-r--r--test/core/compression/stream_compression_test.c31
-rw-r--r--test/core/end2end/fixtures/proxy.c4
-rw-r--r--test/core/end2end/tests/bad_ping.c21
-rw-r--r--test/core/end2end/tests/compressed_payload.c11
-rw-r--r--test/core/end2end/tests/keepalive_timeout.c14
-rw-r--r--test/core/end2end/tests/ping.c18
-rw-r--r--test/core/end2end/tests/resource_quota_server.c12
-rw-r--r--test/core/end2end/tests/simple_request.c20
-rw-r--r--test/core/end2end/tests/stream_compression_compressed_payload.c11
-rw-r--r--test/core/http/httpcli_test.c2
-rw-r--r--test/core/http/httpscli_test.c2
-rw-r--r--test/core/iomgr/endpoint_tests.c9
-rw-r--r--test/core/iomgr/fd_posix_test.c16
-rw-r--r--test/core/iomgr/pollset_set_test.c6
-rw-r--r--test/core/iomgr/resolve_address_test.c6
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c6
-rw-r--r--test/core/iomgr/tcp_client_uv_test.c10
-rw-r--r--test/core/iomgr/tcp_posix_test.c11
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c4
-rw-r--r--test/core/iomgr/tcp_server_uv_test.c4
-rw-r--r--test/core/iomgr/udp_server_test.c8
-rw-r--r--test/core/security/oauth2_utils.c3
-rw-r--r--test/core/security/print_google_default_creds_token.c3
-rw-r--r--test/core/security/verify_jwt.c3
-rw-r--r--test/core/surface/concurrent_connectivity_test.c3
-rw-r--r--test/core/surface/public_headers_must_be_c89.c1
-rw-r--r--test/core/tsi/ssl_transport_security_test.c121
-rw-r--r--test/core/util/port_server_client.c9
-rw-r--r--test/cpp/codegen/compiler_test_golden40
-rw-r--r--test/cpp/codegen/compiler_test_mock_golden5
-rw-r--r--test/cpp/end2end/generic_end2end_test.cc56
-rw-r--r--test/cpp/end2end/grpclb_end2end_test.cc124
-rw-r--r--test/cpp/microbenchmarks/BUILD34
-rw-r--r--test/cpp/microbenchmarks/bm_cq_multiple_threads.cc3
-rw-r--r--test/cpp/microbenchmarks/bm_fullstack_trickle.cc1
-rw-r--r--test/cpp/microbenchmarks/fullstack_fixtures.h1
-rw-r--r--test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h1
-rw-r--r--test/cpp/microbenchmarks/fullstack_streaming_pump.h1
-rw-r--r--test/cpp/microbenchmarks/fullstack_unary_ping_pong.h1
-rw-r--r--test/cpp/naming/BUILD49
-rwxr-xr-xtest/cpp/naming/gen_build_yaml.py99
-rwxr-xr-xtest/cpp/naming/generate_resolver_component_tests.bzl64
-rw-r--r--test/cpp/naming/resolver_component_test.cc326
-rwxr-xr-xtest/cpp/naming/resolver_component_tests_runner.sh181
-rw-r--r--test/cpp/naming/resolver_component_tests_runner_invoker.cc189
-rw-r--r--test/cpp/naming/resolver_test_record_groups.yaml149
-rwxr-xr-xtest/cpp/naming/test_dns_server.py134
-rw-r--r--test/cpp/qps/client_async.cc162
-rw-r--r--test/cpp/qps/report.cc4
-rw-r--r--test/cpp/util/byte_buffer_test.cc5
-rwxr-xr-xtest/distrib/cpp/run_distrib_test_cmake.sh67
-rwxr-xr-xtest/distrib/cpp/run_distrib_test_routeguide.sh (renamed from test/distrib/cpp/run_distrib_test.sh)0
56 files changed, 1824 insertions, 249 deletions
diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c
index f70a9fc880..ba37cd673f 100644
--- a/test/core/client_channel/lb_policies_test.c
+++ b/test/core/client_channel/lb_policies_test.c
@@ -519,7 +519,7 @@ static grpc_channel *create_client(const servers_fixture *f) {
arg_array[1].key = GRPC_ARG_LB_POLICY_NAME;
arg_array[1].value.string = "ROUND_ROBIN";
arg_array[2].type = GRPC_ARG_INTEGER;
- arg_array[2].key = GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS;
+ arg_array[2].key = GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS;
arg_array[2].value.integer = 0;
args.num_args = GPR_ARRAY_SIZE(arg_array);
args.args = arg_array;
diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c
index 51f7d09984..879664ea70 100644
--- a/test/core/compression/algorithm_test.c
+++ b/test/core/compression/algorithm_test.c
@@ -37,7 +37,7 @@ static void test_algorithm_mesh(void) {
gpr_log(GPR_DEBUG, "test_algorithm_mesh");
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
- char *name;
+ const char *name;
grpc_compression_algorithm parsed;
grpc_slice mdstr;
grpc_mdelem mdelem;
diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c
index 4b300e18d3..10f7f07a44 100644
--- a/test/core/compression/compression_test.c
+++ b/test/core/compression/compression_test.c
@@ -57,7 +57,7 @@ static void test_compression_algorithm_parse(void) {
static void test_compression_algorithm_name(void) {
int success;
- char *name;
+ const char *name;
size_t i;
const char *valid_names[] = {"identity", "message/gzip", "message/deflate", "stream/gzip"};
const grpc_compression_algorithm valid_algorithms[] = {
diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c
index 4444b65802..55267f4aa8 100644
--- a/test/core/compression/message_compress_test.c
+++ b/test/core/compression/message_compress_test.c
@@ -49,7 +49,7 @@ static void assert_passthrough(grpc_slice value,
grpc_slice_buffer output;
grpc_slice final;
int was_compressed;
- char *algorithm_name;
+ const char *algorithm_name;
GPR_ASSERT(grpc_message_compression_algorithm_name(algorithm, &algorithm_name) != 0);
gpr_log(
diff --git a/test/core/compression/stream_compression_test.c b/test/core/compression/stream_compression_test.c
index e576507aaf..afed6cd6b5 100644
--- a/test/core/compression/stream_compression_test.c
+++ b/test/core/compression/stream_compression_test.c
@@ -59,10 +59,11 @@ static void test_stream_compression_simple_compress_decompress() {
grpc_slice_buffer_init(&relay);
grpc_slice_buffer_init(&sink);
grpc_stream_compression_context *compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
grpc_stream_compression_context *decompress_ctx =
grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
grpc_slice slice = grpc_slice_from_static_string(test_str);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -91,10 +92,11 @@ test_stream_compression_simple_compress_decompress_with_output_size_constraint()
grpc_slice_buffer_init(&relay);
grpc_slice_buffer_init(&sink);
grpc_stream_compression_context *compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
grpc_stream_compression_context *decompress_ctx =
grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
grpc_slice slice = grpc_slice_from_static_string(test_str);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -139,10 +141,11 @@ test_stream_compression_simple_compress_decompress_with_large_data() {
grpc_slice_buffer_init(&relay);
grpc_slice_buffer_init(&sink);
grpc_stream_compression_context *compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
grpc_stream_compression_context *decompress_ctx =
grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
grpc_slice slice = grpc_slice_from_static_string(test_str);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -172,7 +175,8 @@ static void test_stream_compression_drop_context() {
grpc_slice_buffer_init(&relay);
grpc_slice_buffer_init(&sink);
grpc_stream_compression_context *compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
grpc_slice slice = grpc_slice_from_static_string(test_str);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -180,8 +184,8 @@ static void test_stream_compression_drop_context() {
GRPC_STREAM_COMPRESSION_FLUSH_FINISH));
grpc_stream_compression_context_destroy(compress_ctx);
- compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ compress_ctx = grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
slice = grpc_slice_from_static_string(test_str2);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -205,7 +209,7 @@ static void test_stream_compression_drop_context() {
grpc_stream_compression_context *decompress_ctx =
grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
bool end_of_context;
size_t output_size;
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size,
@@ -219,7 +223,7 @@ static void test_stream_compression_drop_context() {
grpc_slice_buffer_init(&sink);
decompress_ctx = grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size,
~(size_t)0, &end_of_context));
GPR_ASSERT(end_of_context == true);
@@ -240,7 +244,8 @@ static void test_stream_compression_sync_flush() {
grpc_slice_buffer_init(&relay);
grpc_slice_buffer_init(&sink);
grpc_stream_compression_context *compress_ctx =
- grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_COMPRESS);
+ grpc_stream_compression_context_create(
+ GRPC_STREAM_COMPRESSION_GZIP_COMPRESS);
grpc_slice slice = grpc_slice_from_static_string(test_str);
grpc_slice_buffer_add(&source, slice);
GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL,
@@ -249,7 +254,7 @@ static void test_stream_compression_sync_flush() {
grpc_stream_compression_context *decompress_ctx =
grpc_stream_compression_context_create(
- GRPC_STREAM_COMPRESSION_DECOMPRESS);
+ GRPC_STREAM_COMPRESSION_GZIP_DECOMPRESS);
bool end_of_context;
size_t output_size;
GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size,
diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c
index 9ad862728f..6a2d75da09 100644
--- a/test/core/end2end/fixtures/proxy.c
+++ b/test/core/end2end/fixtures/proxy.c
@@ -227,6 +227,10 @@ static void on_c2p_recv_msg(void *arg, int success) {
new_closure(on_p2s_sent_close, pc), NULL);
GPR_ASSERT(err == GRPC_CALL_OK);
}
+ } else {
+ if (pc->c2p_msg != NULL) {
+ grpc_byte_buffer_destroy(pc->c2p_msg);
+ }
}
unrefpc(pc, "on_c2p_recv_msg");
diff --git a/test/core/end2end/tests/bad_ping.c b/test/core/end2end/tests/bad_ping.c
index 12aceda688..c97d11b306 100644
--- a/test/core/end2end/tests/bad_ping.c
+++ b/test/core/end2end/tests/bad_ping.c
@@ -66,18 +66,19 @@ static void end_test(grpc_end2end_test_fixture *f) {
static void test_bad_ping(grpc_end2end_test_config config) {
grpc_end2end_test_fixture f = config.create_fixture(NULL, NULL);
cq_verifier *cqv = cq_verifier_create(f.cq);
- grpc_arg client_a[] = {{.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS,
- .value.integer = 0},
- {.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA,
- .value.integer = 20},
- {.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_BDP_PROBE,
- .value.integer = 0}};
+ grpc_arg client_a[] = {
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS,
+ .value.integer = 10},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA,
+ .value.integer = 0},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_BDP_PROBE,
+ .value.integer = 0}};
grpc_arg server_a[] = {
{.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS,
+ .key = GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS,
.value.integer = 300000 /* 5 minutes */},
{.type = GRPC_ARG_INTEGER,
.key = GRPC_ARG_HTTP2_MAX_PING_STRIKES,
diff --git a/test/core/end2end/tests/compressed_payload.c b/test/core/end2end/tests/compressed_payload.c
index e07199ac28..a11e24d3a1 100644
--- a/test/core/end2end/tests/compressed_payload.c
+++ b/test/core/end2end/tests/compressed_payload.c
@@ -151,6 +151,11 @@ static void request_for_disabled_algorithm(
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
+ error =
+ grpc_server_request_call(f.server, &s, &call_details,
+ &request_metadata_recv, f.cq, f.cq, tag(101));
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
@@ -187,10 +192,6 @@ static void request_for_disabled_algorithm(
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
- error =
- grpc_server_request_call(f.server, &s, &call_details,
- &request_metadata_recv, f.cq, f.cq, tag(101));
- GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(101), true);
cq_verify(cqv);
@@ -228,7 +229,7 @@ static void request_for_disabled_algorithm(
/* with a certain error */
GPR_ASSERT(status == expected_error);
- char *algo_name = NULL;
+ const char *algo_name = NULL;
GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name));
char *expected_details = NULL;
gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.",
diff --git a/test/core/end2end/tests/keepalive_timeout.c b/test/core/end2end/tests/keepalive_timeout.c
index e0ead4ab62..8d01f23c00 100644
--- a/test/core/end2end/tests/keepalive_timeout.c
+++ b/test/core/end2end/tests/keepalive_timeout.c
@@ -106,13 +106,13 @@ static void test_keepalive_timeout(grpc_end2end_test_config config) {
.value.integer = 0},
{.type = GRPC_ARG_INTEGER,
.key = GRPC_ARG_HTTP2_BDP_PROBE,
- .value.integer = 1}};
+ .value.integer = 0}};
- grpc_channel_args *client_args = NULL;
- client_args = grpc_channel_args_copy_and_add(client_args, keepalive_args, 2);
+ grpc_channel_args client_args = {.num_args = GPR_ARRAY_SIZE(keepalive_args),
+ .args = keepalive_args};
grpc_end2end_test_fixture f =
- begin_test(config, "keepalive_timeout", client_args, NULL);
+ begin_test(config, "keepalive_timeout", &client_args, NULL);
cq_verifier *cqv = cq_verifier_create(f.cq);
grpc_op ops[6];
grpc_op *op;
@@ -216,12 +216,6 @@ static void test_keepalive_timeout(grpc_end2end_test_config config) {
grpc_byte_buffer_destroy(response_payload);
grpc_byte_buffer_destroy(response_payload_recv);
- if (client_args != NULL) {
- grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_channel_args_destroy(&exec_ctx, client_args);
- grpc_exec_ctx_finish(&exec_ctx);
- }
-
end_test(&f);
config.tear_down_data(&f);
}
diff --git a/test/core/end2end/tests/ping.c b/test/core/end2end/tests/ping.c
index 112ad9d7d2..23c82569ba 100644
--- a/test/core/end2end/tests/ping.c
+++ b/test/core/end2end/tests/ping.c
@@ -37,15 +37,19 @@ static void test_ping(grpc_end2end_test_config config,
grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
int i;
- grpc_arg client_a[] = {{.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS,
- .value.integer = 0},
- {.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA,
- .value.integer = 20}};
+ grpc_arg client_a[] = {
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS,
+ .value.integer = 10},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA,
+ .value.integer = 0},
+ {.type = GRPC_ARG_INTEGER,
+ .key = GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS,
+ .value.integer = 1}};
grpc_arg server_a[] = {
{.type = GRPC_ARG_INTEGER,
- .key = GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS,
+ .key = GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS,
.value.integer = 0},
{.type = GRPC_ARG_INTEGER,
.key = GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS,
diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c
index 0316920762..93befeee0c 100644
--- a/test/core/end2end/tests/resource_quota_server.c
+++ b/test/core/end2end/tests/resource_quota_server.c
@@ -136,20 +136,20 @@ void resource_quota_server(grpc_end2end_test_config config) {
grpc_call **server_calls =
(grpc_call **)malloc(sizeof(grpc_call *) * NUM_CALLS);
grpc_metadata_array *initial_metadata_recv =
- malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
+ (grpc_metadata_array *)malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
grpc_metadata_array *trailing_metadata_recv =
- malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
+ (grpc_metadata_array *)malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
grpc_metadata_array *request_metadata_recv =
- malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
+ (grpc_metadata_array *)malloc(sizeof(grpc_metadata_array) * NUM_CALLS);
grpc_call_details *call_details =
- malloc(sizeof(grpc_call_details) * NUM_CALLS);
+ (grpc_call_details *)malloc(sizeof(grpc_call_details) * NUM_CALLS);
grpc_status_code *status =
(grpc_status_code *)malloc(sizeof(grpc_status_code) * NUM_CALLS);
grpc_slice *details = (grpc_slice *)malloc(sizeof(grpc_slice) * NUM_CALLS);
grpc_byte_buffer **request_payload =
- malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS);
+ (grpc_byte_buffer **)malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS);
grpc_byte_buffer **request_payload_recv =
- malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS);
+ (grpc_byte_buffer **)malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS);
int *was_cancelled = (int *)malloc(sizeof(int) * NUM_CALLS);
grpc_call_error error;
int pending_client_calls = 0;
diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c
index 82ab0a1cfe..7ce7e1f285 100644
--- a/test/core/end2end/tests/simple_request.c
+++ b/test/core/end2end/tests/simple_request.c
@@ -103,10 +103,10 @@ static void simple_request_body(grpc_end2end_test_config config,
grpc_slice details;
int was_cancelled = 2;
char *peer;
- grpc_stats_data before;
- grpc_stats_data after;
+ grpc_stats_data *before = gpr_malloc(sizeof(grpc_stats_data));
+ grpc_stats_data *after = gpr_malloc(sizeof(grpc_stats_data));
- grpc_stats_collect(&before);
+ grpc_stats_collect(before);
gpr_timespec deadline = five_seconds_from_now();
c = grpc_channel_create_call(
@@ -214,9 +214,9 @@ static void simple_request_body(grpc_end2end_test_config config,
cq_verifier_destroy(cqv);
- grpc_stats_collect(&after);
+ grpc_stats_collect(after);
- char *stats = grpc_stats_data_as_json(&after);
+ char *stats = grpc_stats_data_as_json(after);
gpr_log(GPR_DEBUG, "%s", stats);
gpr_free(stats);
@@ -224,12 +224,14 @@ static void simple_request_body(grpc_end2end_test_config config,
if (config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) {
expected_calls *= 2;
}
- GPR_ASSERT(after.counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] -
- before.counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] ==
+ GPR_ASSERT(after->counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] -
+ before->counters[GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED] ==
expected_calls);
- GPR_ASSERT(after.counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] -
- before.counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] ==
+ GPR_ASSERT(after->counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] -
+ before->counters[GRPC_STATS_COUNTER_SERVER_CALLS_CREATED] ==
expected_calls);
+ gpr_free(before);
+ gpr_free(after);
}
static void test_invoke_simple_request(grpc_end2end_test_config config) {
diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.c b/test/core/end2end/tests/stream_compression_compressed_payload.c
index 87c3183534..ce7598c508 100644
--- a/test/core/end2end/tests/stream_compression_compressed_payload.c
+++ b/test/core/end2end/tests/stream_compression_compressed_payload.c
@@ -151,6 +151,11 @@ static void request_for_disabled_algorithm(
grpc_metadata_array_init(&request_metadata_recv);
grpc_call_details_init(&call_details);
+ error =
+ grpc_server_request_call(f.server, &s, &call_details,
+ &request_metadata_recv, f.cq, f.cq, tag(101));
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
@@ -187,10 +192,6 @@ static void request_for_disabled_algorithm(
error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
- error =
- grpc_server_request_call(f.server, &s, &call_details,
- &request_metadata_recv, f.cq, f.cq, tag(101));
- GPR_ASSERT(GRPC_CALL_OK == error);
CQ_EXPECT_COMPLETION(cqv, tag(101), true);
cq_verify(cqv);
@@ -228,7 +229,7 @@ static void request_for_disabled_algorithm(
/* with a certain error */
GPR_ASSERT(status == expected_error);
- char *algo_name = NULL;
+ const char *algo_name = NULL;
GPR_ASSERT(grpc_compression_algorithm_name(algorithm_to_disable, &algo_name));
char *expected_details = NULL;
gpr_asprintf(&expected_details,
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c
index b8b96d673c..8a53903763 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.c
@@ -52,7 +52,7 @@ static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
g_done = 1;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), NULL)));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c
index a9d7abdcff..c7455bd8df 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.c
@@ -52,7 +52,7 @@ static void on_finish(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
g_done = 1;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&g_pops), NULL)));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&g_pops), NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 895cc0e158..f8570edde7 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -126,7 +126,8 @@ static void read_and_write_test_read_handler(grpc_exec_ctx *exec_ctx,
gpr_log(GPR_INFO, "Read handler done");
gpr_mu_lock(g_mu);
state->read_done = 1 + (error == GRPC_ERROR_NONE);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL));
gpr_mu_unlock(g_mu);
} else if (error == GRPC_ERROR_NONE) {
grpc_endpoint_read(exec_ctx, state->read_ep, &state->incoming,
@@ -162,7 +163,8 @@ static void read_and_write_test_write_handler(grpc_exec_ctx *exec_ctx,
gpr_log(GPR_INFO, "Write handler done");
gpr_mu_lock(g_mu);
state->write_done = 1 + (error == GRPC_ERROR_NONE);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL));
gpr_mu_unlock(g_mu);
}
@@ -254,7 +256,8 @@ static void inc_on_failure(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
gpr_mu_lock(g_mu);
*(int *)arg += (error != GRPC_ERROR_NONE);
- GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(
+ GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 5791d17af6..881277a8d6 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -178,8 +178,8 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */,
gpr_mu_lock(g_mu);
sv->done = 1;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -297,8 +297,8 @@ static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx,
grpc_fd_orphan(exec_ctx, cl->em_fd, NULL, NULL, false /* already_closed */,
"c");
cl->done = 1;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
}
/* Write as much as possible, then register notify_on_write. */
@@ -417,8 +417,8 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(g_mu);
fdc->cb_that_ran = first_read_callback;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -429,8 +429,8 @@ static void second_read_callback(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(g_mu);
fdc->cb_that_ran = second_read_callback;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c
index 5750ac0f4b..70efca8b16 100644
--- a/test/core/iomgr/pollset_set_test.c
+++ b/test/core/iomgr/pollset_set_test.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <unistd.h>
+#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
@@ -433,8 +434,7 @@ int main(int argc, char **argv) {
const char *poll_strategy = grpc_get_poll_strategy_name();
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_test_init(argc, argv);
- grpc_iomgr_init(&exec_ctx);
- grpc_iomgr_start(&exec_ctx);
+ grpc_init();
if (poll_strategy != NULL &&
(strcmp(poll_strategy, "epoll") == 0 ||
@@ -449,8 +449,8 @@ int main(int argc, char **argv) {
poll_strategy);
}
- grpc_iomgr_shutdown(&exec_ctx);
grpc_exec_ctx_finish(&exec_ctx);
+ grpc_shutdown();
return 0;
}
#else /* defined(GRPC_LINUX_EPOLL) */
diff --git a/test/core/iomgr/resolve_address_test.c b/test/core/iomgr/resolve_address_test.c
index 7f5c4073d8..1110c04b6e 100644
--- a/test/core/iomgr/resolve_address_test.c
+++ b/test/core/iomgr/resolve_address_test.c
@@ -106,7 +106,8 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *argsp,
GPR_ASSERT(args->addrs->naddrs > 0);
gpr_atm_rel_store(&args->done_atm, 1);
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, args->pollset, NULL));
gpr_mu_unlock(args->mu);
}
@@ -115,7 +116,8 @@ static void must_fail(grpc_exec_ctx *exec_ctx, void *argsp, grpc_error *err) {
GPR_ASSERT(err != GRPC_ERROR_NONE);
gpr_atm_rel_store(&args->done_atm, 1);
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, args->pollset, NULL));
gpr_mu_unlock(args->mu);
}
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index 00ea495bbe..1032da942b 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -53,8 +53,10 @@ static gpr_timespec test_deadline(void) {
static void finish_connection() {
gpr_mu_lock(g_mu);
g_connections_complete++;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(&exec_ctx, g_pollset, NULL)));
+ grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/tcp_client_uv_test.c b/test/core/iomgr/tcp_client_uv_test.c
index 9927356613..0f1db4705b 100644
--- a/test/core/iomgr/tcp_client_uv_test.c
+++ b/test/core/iomgr/tcp_client_uv_test.c
@@ -46,11 +46,11 @@ static gpr_timespec test_deadline(void) {
return grpc_timeout_seconds_to_deadline(10);
}
-static void finish_connection() {
+static void finish_connection(grpc_exec_ctx *exec_ctx) {
gpr_mu_lock(g_mu);
g_connections_complete++;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -63,13 +63,13 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called"));
grpc_endpoint_destroy(exec_ctx, g_connecting);
g_connecting = NULL;
- finish_connection();
+ finish_connection(exec_ctx);
}
static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
GPR_ASSERT(g_connecting == NULL);
GPR_ASSERT(error != GRPC_ERROR_NONE);
- finish_connection();
+ finish_connection(exec_ctx);
}
static void close_cb(uv_handle_t *handle) { gpr_free(handle); }
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index cdaa2ce2af..cfb3cf897c 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -147,7 +147,8 @@ static void read_cb(grpc_exec_ctx *exec_ctx, void *user_data,
gpr_log(GPR_INFO, "Read %" PRIuPTR " bytes of %" PRIuPTR, read_bytes,
state->target_read_bytes);
if (state->read_bytes >= state->target_read_bytes) {
- GPR_ASSERT(GRPC_LOG_IF_ERROR("kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
} else {
grpc_endpoint_read(exec_ctx, state->ep, &state->incoming, &state->read_cb);
@@ -295,8 +296,8 @@ static void write_done(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(g_mu);
gpr_log(GPR_INFO, "Signalling write done");
state->write_done = 1;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -406,8 +407,8 @@ static void write_test(size_t num_bytes, size_t slice_size) {
void on_fd_released(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *errors) {
int *done = (int *)arg;
*done = 1;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
}
/* Do a read_test, then release fd and try to read/write again. Verify that
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 2371721a60..4d84608376 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -159,8 +159,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
gpr_mu_lock(g_mu);
g_result = temp_result;
g_nconnects++;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/tcp_server_uv_test.c b/test/core/iomgr/tcp_server_uv_test.c
index 8f4d553d1e..bd8ccb4f60 100644
--- a/test/core/iomgr/tcp_server_uv_test.c
+++ b/test/core/iomgr/tcp_server_uv_test.c
@@ -111,8 +111,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
gpr_mu_lock(g_mu);
g_result = temp_result;
g_nconnects++;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index aa34857dbd..1d051bea62 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -61,8 +61,8 @@ static void on_read(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, void *user_data) {
g_number_of_reads++;
g_number_of_bytes_read += (int)byte_count;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
@@ -70,8 +70,8 @@ static void on_write(grpc_exec_ctx *exec_ctx, grpc_fd *emfd, void *user_data) {
gpr_mu_lock(g_mu);
g_number_of_writes++;
- GPR_ASSERT(
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(g_pollset, NULL)));
+ GPR_ASSERT(GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, g_pollset, NULL)));
gpr_mu_unlock(g_mu);
}
diff --git a/test/core/security/oauth2_utils.c b/test/core/security/oauth2_utils.c
index fdbc6ea741..d240403a29 100644
--- a/test/core/security/oauth2_utils.c
+++ b/test/core/security/oauth2_utils.c
@@ -60,7 +60,8 @@ static void on_oauth2_response(grpc_exec_ctx *exec_ctx, void *arg,
request->token = token;
GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&request->pops), NULL));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&request->pops),
+ NULL));
gpr_mu_unlock(request->mu);
}
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index e1385a80ca..3144717a85 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -57,7 +57,8 @@ static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *arg,
sync->is_done = true;
GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&sync->pops), NULL));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&sync->pops),
+ NULL));
gpr_mu_unlock(sync->mu);
}
diff --git a/test/core/security/verify_jwt.c b/test/core/security/verify_jwt.c
index 259038f4d6..5faa6352a8 100644
--- a/test/core/security/verify_jwt.c
+++ b/test/core/security/verify_jwt.c
@@ -66,7 +66,8 @@ static void on_jwt_verification_done(grpc_exec_ctx *exec_ctx, void *user_data,
gpr_mu_lock(sync->mu);
sync->is_done = 1;
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(sync->pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, sync->pollset, NULL));
gpr_mu_unlock(sync->mu);
}
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index 08079b6091..ec2cd8610b 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -108,7 +108,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *vargs, grpc_endpoint *tcp,
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(exec_ctx, tcp);
gpr_mu_lock(args->mu);
- GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, NULL));
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, args->pollset, NULL));
gpr_mu_unlock(args->mu);
}
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index 0d7f68c0ad..d36d116afb 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -24,6 +24,7 @@
#include <grpc/grpc_security.h>
#include <grpc/grpc_security_constants.h>
#include <grpc/impl/codegen/atm.h>
+#include <grpc/impl/codegen/byte_buffer.h>
#include <grpc/impl/codegen/byte_buffer_reader.h>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/connectivity_state.h>
diff --git a/test/core/tsi/ssl_transport_security_test.c b/test/core/tsi/ssl_transport_security_test.c
index 364dfa1b73..2399b054b1 100644
--- a/test/core/tsi/ssl_transport_security_test.c
+++ b/test/core/tsi/ssl_transport_security_test.c
@@ -23,7 +23,9 @@
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/transport/security_connector.h"
#include "src/core/tsi/ssl_transport_security.h"
+#include "src/core/tsi/transport_security.h"
#include "src/core/tsi/transport_security_adapter.h"
+#include "src/core/tsi/transport_security_interface.h"
#include "test/core/tsi/transport_security_test_lib.h"
#include "test/core/util/test_config.h"
@@ -312,10 +314,10 @@ static void ssl_test_destruct(tsi_test_fixture *fixture) {
key_cert_lib->bad_client_pem_key_cert_pair);
gpr_free(key_cert_lib->root_cert);
gpr_free(key_cert_lib);
- /* Destroy others. */
- tsi_ssl_server_handshaker_factory_destroy(
+ /* Unreference others. */
+ tsi_ssl_server_handshaker_factory_unref(
ssl_fixture->server_handshaker_factory);
- tsi_ssl_client_handshaker_factory_destroy(
+ tsi_ssl_client_handshaker_factory_unref(
ssl_fixture->client_handshaker_factory);
}
@@ -536,6 +538,118 @@ void ssl_tsi_test_do_round_trip_odd_buffer_size() {
}
}
+static const tsi_ssl_handshaker_factory_vtable *original_vtable;
+static bool handshaker_factory_destructor_called;
+
+static void ssl_tsi_test_handshaker_factory_destructor(
+ tsi_ssl_handshaker_factory *factory) {
+ GPR_ASSERT(factory != NULL);
+ handshaker_factory_destructor_called = true;
+ if (original_vtable != NULL && original_vtable->destroy != NULL) {
+ original_vtable->destroy(factory);
+ }
+}
+
+static tsi_ssl_handshaker_factory_vtable test_handshaker_factory_vtable = {
+ ssl_tsi_test_handshaker_factory_destructor};
+
+void test_tsi_ssl_client_handshaker_factory_refcounting() {
+ int i;
+ const char *cert_chain =
+ load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "client.pem");
+
+ tsi_ssl_client_handshaker_factory *client_handshaker_factory;
+ GPR_ASSERT(tsi_create_ssl_client_handshaker_factory(
+ NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) ==
+ TSI_OK);
+
+ handshaker_factory_destructor_called = false;
+ original_vtable = tsi_ssl_handshaker_factory_swap_vtable(
+ (tsi_ssl_handshaker_factory *)client_handshaker_factory,
+ &test_handshaker_factory_vtable);
+
+ tsi_handshaker *handshaker[3];
+
+ for (i = 0; i < 3; ++i) {
+ GPR_ASSERT(tsi_ssl_client_handshaker_factory_create_handshaker(
+ client_handshaker_factory, "google.com", &handshaker[i]) ==
+ TSI_OK);
+ }
+
+ tsi_handshaker_destroy(handshaker[1]);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_handshaker_destroy(handshaker[0]);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_handshaker_destroy(handshaker[2]);
+ GPR_ASSERT(handshaker_factory_destructor_called);
+
+ gpr_free((void *)cert_chain);
+}
+
+void test_tsi_ssl_server_handshaker_factory_refcounting() {
+ int i;
+ tsi_ssl_server_handshaker_factory *server_handshaker_factory;
+ tsi_handshaker *handshaker[3];
+ const char *cert_chain =
+ load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.pem");
+ tsi_ssl_pem_key_cert_pair cert_pair;
+
+ cert_pair.cert_chain = cert_chain;
+ cert_pair.private_key =
+ load_file(SSL_TSI_TEST_CREDENTIALS_DIR, "server0.key");
+
+ GPR_ASSERT(tsi_create_ssl_server_handshaker_factory(
+ &cert_pair, 1, cert_chain, 0, NULL, NULL, 0,
+ &server_handshaker_factory) == TSI_OK);
+
+ handshaker_factory_destructor_called = false;
+ original_vtable = tsi_ssl_handshaker_factory_swap_vtable(
+ (tsi_ssl_handshaker_factory *)server_handshaker_factory,
+ &test_handshaker_factory_vtable);
+
+ for (i = 0; i < 3; ++i) {
+ GPR_ASSERT(tsi_ssl_server_handshaker_factory_create_handshaker(
+ server_handshaker_factory, &handshaker[i]) == TSI_OK);
+ }
+
+ tsi_handshaker_destroy(handshaker[1]);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_handshaker_destroy(handshaker[0]);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_ssl_server_handshaker_factory_unref(server_handshaker_factory);
+ GPR_ASSERT(!handshaker_factory_destructor_called);
+
+ tsi_handshaker_destroy(handshaker[2]);
+ GPR_ASSERT(handshaker_factory_destructor_called);
+
+ ssl_test_pem_key_cert_pair_destroy(cert_pair);
+}
+
+/* Attempting to create a handshaker factory with invalid parameters should fail
+ * but not crash. */
+void test_tsi_ssl_client_handshaker_factory_bad_params() {
+ const char *cert_chain = "This is not a valid PEM file.";
+
+ tsi_ssl_client_handshaker_factory *client_handshaker_factory;
+ GPR_ASSERT(tsi_create_ssl_client_handshaker_factory(
+ NULL, cert_chain, NULL, NULL, 0, &client_handshaker_factory) ==
+ TSI_INVALID_ARGUMENT);
+ tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory);
+}
+
+void ssl_tsi_test_handshaker_factory_internals() {
+ test_tsi_ssl_client_handshaker_factory_refcounting();
+ test_tsi_ssl_server_handshaker_factory_refcounting();
+ test_tsi_ssl_client_handshaker_factory_bad_params();
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
@@ -553,6 +667,7 @@ int main(int argc, char **argv) {
ssl_tsi_test_do_handshake_alpn_client_server_ok();
ssl_tsi_test_do_round_trip_for_all_configs();
ssl_tsi_test_do_round_trip_odd_buffer_size();
+ ssl_tsi_test_handshaker_factory_internals();
grpc_shutdown();
return 0;
}
diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c
index 851c50941e..ba4028dbee 100644
--- a/test/core/util/port_server_client.c
+++ b/test/core/util/port_server_client.c
@@ -54,7 +54,8 @@ static void freed_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
pr->done = 1;
GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), NULL));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops),
+ NULL));
gpr_mu_unlock(pr->mu);
}
@@ -153,7 +154,8 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
pr->port = 0;
GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), NULL));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops),
+ NULL));
gpr_mu_unlock(pr->mu);
return;
}
@@ -189,7 +191,8 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg,
pr->port = port;
GRPC_LOG_IF_ERROR(
"pollset_kick",
- grpc_pollset_kick(grpc_polling_entity_pollset(&pr->pops), NULL));
+ grpc_pollset_kick(exec_ctx, grpc_polling_entity_pollset(&pr->pops),
+ NULL));
gpr_mu_unlock(pr->mu);
}
diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden
index b43c27f3f7..3d664e8825 100644
--- a/test/cpp/codegen/compiler_test_golden
+++ b/test/cpp/codegen/compiler_test_golden
@@ -65,6 +65,9 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>> AsyncMethodA1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>>(AsyncMethodA1Raw(context, request, cq));
}
+ std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>> PrepareAsyncMethodA1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>>(PrepareAsyncMethodA1Raw(context, request, cq));
+ }
// MethodA1 trailing comment 1
// MethodA2 detached leading comment 1
//
@@ -76,6 +79,9 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>> AsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>> PrepareAsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>>(PrepareAsyncMethodA2Raw(context, response, cq));
+ }
// MethodA2 trailing comment 1
// Method A3 leading comment 1
std::unique_ptr< ::grpc::ClientReaderInterface< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) {
@@ -84,6 +90,9 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>> PrepareAsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>>(PrepareAsyncMethodA3Raw(context, request, cq));
+ }
// Method A3 trailing comment 1
// Method A4 leading comment 1
std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) {
@@ -92,15 +101,22 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>> PrepareAsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>>(PrepareAsyncMethodA4Raw(context, cq));
+ }
// Method A4 trailing comment 1
private:
virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
+ virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* PrepareAsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientWriterInterface< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) = 0;
virtual ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) = 0;
+ virtual ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>* PrepareAsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientReaderInterface< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) = 0;
virtual ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) = 0;
+ virtual ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>* PrepareAsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) = 0;
virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0;
+ virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>* PrepareAsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) = 0;
};
class Stub final : public StubInterface {
public:
@@ -109,34 +125,50 @@ class ServiceA final {
std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>> AsyncMethodA1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>>(AsyncMethodA1Raw(context, request, cq));
}
+ std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>> PrepareAsyncMethodA1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>>(PrepareAsyncMethodA1Raw(context, request, cq));
+ }
std::unique_ptr< ::grpc::ClientWriter< ::grpc::testing::Request>> MethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response) {
return std::unique_ptr< ::grpc::ClientWriter< ::grpc::testing::Request>>(MethodA2Raw(context, response));
}
std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>> AsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>>(AsyncMethodA2Raw(context, response, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>> PrepareAsyncMethodA2(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncWriter< ::grpc::testing::Request>>(PrepareAsyncMethodA2Raw(context, response, cq));
+ }
std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>> MethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request) {
return std::unique_ptr< ::grpc::ClientReader< ::grpc::testing::Response>>(MethodA3Raw(context, request));
}
std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>> AsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>>(AsyncMethodA3Raw(context, request, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>> PrepareAsyncMethodA3(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncReader< ::grpc::testing::Response>>(PrepareAsyncMethodA3Raw(context, request, cq));
+ }
std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> MethodA4(::grpc::ClientContext* context) {
return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(MethodA4Raw(context));
}
std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> AsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) {
return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(AsyncMethodA4Raw(context, cq, tag));
}
+ std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>> PrepareAsyncMethodA4(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>>(PrepareAsyncMethodA4Raw(context, cq));
+ }
private:
std::shared_ptr< ::grpc::ChannelInterface> channel_;
::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* AsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
+ ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* PrepareAsyncMethodA1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
::grpc::ClientWriter< ::grpc::testing::Request>* MethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response) override;
::grpc::ClientAsyncWriter< ::grpc::testing::Request>* AsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag) override;
+ ::grpc::ClientAsyncWriter< ::grpc::testing::Request>* PrepareAsyncMethodA2Raw(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq) override;
::grpc::ClientReader< ::grpc::testing::Response>* MethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request) override;
::grpc::ClientAsyncReader< ::grpc::testing::Response>* AsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag) override;
+ ::grpc::ClientAsyncReader< ::grpc::testing::Response>* PrepareAsyncMethodA3Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
::grpc::ClientReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* MethodA4Raw(::grpc::ClientContext* context) override;
::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* AsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) override;
+ ::grpc::ClientAsyncReaderWriter< ::grpc::testing::Request, ::grpc::testing::Response>* PrepareAsyncMethodA4Raw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) override;
const ::grpc::RpcMethod rpcmethod_MethodA1_;
const ::grpc::RpcMethod rpcmethod_MethodA2_;
const ::grpc::RpcMethod rpcmethod_MethodA3_;
@@ -372,9 +404,13 @@ class ServiceB final {
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>> AsyncMethodB1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>>(AsyncMethodB1Raw(context, request, cq));
}
+ std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>> PrepareAsyncMethodB1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>>(PrepareAsyncMethodB1Raw(context, request, cq));
+ }
// MethodB1 trailing comment 1
private:
virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* AsyncMethodB1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
+ virtual ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>* PrepareAsyncMethodB1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) = 0;
};
class Stub final : public StubInterface {
public:
@@ -383,10 +419,14 @@ class ServiceB final {
std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>> AsyncMethodB1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>>(AsyncMethodB1Raw(context, request, cq));
}
+ std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>> PrepareAsyncMethodB1(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) {
+ return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>>(PrepareAsyncMethodB1Raw(context, request, cq));
+ }
private:
std::shared_ptr< ::grpc::ChannelInterface> channel_;
::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* AsyncMethodB1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
+ ::grpc::ClientAsyncResponseReader< ::grpc::testing::Response>* PrepareAsyncMethodB1Raw(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq) override;
const ::grpc::RpcMethod rpcmethod_MethodB1_;
};
static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
diff --git a/test/cpp/codegen/compiler_test_mock_golden b/test/cpp/codegen/compiler_test_mock_golden
index 8e4b4d5911..f97c2dd83a 100644
--- a/test/cpp/codegen/compiler_test_mock_golden
+++ b/test/cpp/codegen/compiler_test_mock_golden
@@ -15,18 +15,23 @@ class MockServiceAStub : public ServiceA::StubInterface {
public:
MOCK_METHOD3(MethodA1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response));
MOCK_METHOD3(AsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
+ MOCK_METHOD3(PrepareAsyncMethodA1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
MOCK_METHOD2(MethodA2Raw, ::grpc::ClientWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response));
MOCK_METHOD4(AsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq, void* tag));
+ MOCK_METHOD3(PrepareAsyncMethodA2Raw, ::grpc::ClientAsyncWriterInterface< ::grpc::testing::Request>*(::grpc::ClientContext* context, ::grpc::testing::Response* response, ::grpc::CompletionQueue* cq));
MOCK_METHOD2(MethodA3Raw, ::grpc::ClientReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request));
MOCK_METHOD4(AsyncMethodA3Raw, ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq, void* tag));
+ MOCK_METHOD3(PrepareAsyncMethodA3Raw, ::grpc::ClientAsyncReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
MOCK_METHOD1(MethodA4Raw, ::grpc::ClientReaderWriterInterface< ::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context));
MOCK_METHOD3(AsyncMethodA4Raw, ::grpc::ClientAsyncReaderWriterInterface<::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag));
+ MOCK_METHOD2(PrepareAsyncMethodA4Raw, ::grpc::ClientAsyncReaderWriterInterface<::grpc::testing::Request, ::grpc::testing::Response>*(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq));
};
class MockServiceBStub : public ServiceB::StubInterface {
public:
MOCK_METHOD3(MethodB1, ::grpc::Status(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::testing::Response* response));
MOCK_METHOD3(AsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
+ MOCK_METHOD3(PrepareAsyncMethodB1Raw, ::grpc::ClientAsyncResponseReaderInterface< ::grpc::testing::Response>*(::grpc::ClientContext* context, const ::grpc::testing::Request& request, ::grpc::CompletionQueue* cq));
};
} // namespace grpc
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index b9e6e18ca7..33b35108d2 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -196,6 +196,62 @@ TEST_F(GenericEnd2endTest, SequentialRpcs) {
SendRpc(10);
}
+TEST_F(GenericEnd2endTest, SequentialUnaryRpcs) {
+ ResetStub();
+ const int num_rpcs = 10;
+ const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo");
+ for (int i = 0; i < num_rpcs; i++) {
+ EchoRequest send_request;
+ EchoRequest recv_request;
+ EchoResponse send_response;
+ EchoResponse recv_response;
+ Status recv_status;
+
+ ClientContext cli_ctx;
+ GenericServerContext srv_ctx;
+ GenericServerAsyncReaderWriter stream(&srv_ctx);
+
+ // The string needs to be long enough to test heap-based slice.
+ send_request.set_message("Hello world. Hello world. Hello world.");
+
+ std::unique_ptr<ByteBuffer> cli_send_buffer =
+ SerializeToByteBuffer(&send_request);
+ std::unique_ptr<GenericClientAsyncResponseReader> call =
+ generic_stub_->PrepareUnaryCall(&cli_ctx, kMethodName,
+ *cli_send_buffer.get(), &cli_cq_);
+ call->StartCall();
+ ByteBuffer cli_recv_buffer;
+ call->Finish(&cli_recv_buffer, &recv_status, tag(1));
+
+ generic_service_.RequestCall(&srv_ctx, &stream, srv_cq_.get(),
+ srv_cq_.get(), tag(4));
+
+ verify_ok(srv_cq_.get(), 4, true);
+ EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
+ EXPECT_EQ(kMethodName, srv_ctx.method());
+
+ ByteBuffer srv_recv_buffer;
+ stream.Read(&srv_recv_buffer, tag(5));
+ server_ok(5);
+ EXPECT_TRUE(ParseFromByteBuffer(&srv_recv_buffer, &recv_request));
+ EXPECT_EQ(send_request.message(), recv_request.message());
+
+ send_response.set_message(recv_request.message());
+ std::unique_ptr<ByteBuffer> srv_send_buffer =
+ SerializeToByteBuffer(&send_response);
+ stream.Write(*srv_send_buffer, tag(6));
+ server_ok(6);
+
+ stream.Finish(Status::OK, tag(7));
+ server_ok(7);
+
+ client_ok(1);
+ EXPECT_TRUE(ParseFromByteBuffer(&cli_recv_buffer, &recv_response));
+ EXPECT_EQ(send_response.message(), recv_response.message());
+ EXPECT_TRUE(recv_status.ok());
+ }
+}
+
// One ping, one pong.
TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
ResetStub();
diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc
index 570a3d1067..77ed155292 100644
--- a/test/cpp/end2end/grpclb_end2end_test.cc
+++ b/test/cpp/end2end/grpclb_end2end_test.cc
@@ -398,11 +398,40 @@ class GrpclbEnd2endTest : public ::testing::Test {
return true;
}
- void WaitForAllBackends() {
+ void SendRpcAndCount(int* num_total, int* num_ok, int* num_failure,
+ int* num_drops) {
+ const Status status = SendRpc();
+ if (status.ok()) {
+ ++*num_ok;
+ } else {
+ if (status.error_message() == "Call dropped by load balancing policy") {
+ ++*num_drops;
+ } else {
+ ++*num_failure;
+ }
+ }
+ ++*num_total;
+ }
+
+ std::tuple<int, int, int> WaitForAllBackends(
+ int num_requests_multiple_of = 1) {
+ int num_ok = 0;
+ int num_failure = 0;
+ int num_drops = 0;
+ int num_total = 0;
while (!SeenAllBackends()) {
- CheckRpcSendOk();
+ SendRpcAndCount(&num_total, &num_ok, &num_failure, &num_drops);
+ }
+ while (num_total % num_requests_multiple_of != 0) {
+ SendRpcAndCount(&num_total, &num_ok, &num_failure, &num_drops);
}
ResetBackendCounters();
+ gpr_log(GPR_INFO,
+ "Performed %d warm up requests (a multiple of %d) against the "
+ "backends. %d succeeded, %d failed, %d dropped.",
+ num_total, num_requests_multiple_of, num_ok, num_failure,
+ num_drops);
+ return std::make_tuple(num_ok, num_failure, num_drops);
}
void WaitForBackend(size_t backend_idx) {
@@ -556,10 +585,8 @@ TEST_F(SingleBalancerTest, Vanilla) {
0);
// Make sure that trying to connect works without a call.
channel_->GetState(true /* try_to_connect */);
-
// We need to wait for all backends to come online.
WaitForAllBackends();
-
// Send kNumRpcsPerAddress RPCs per server.
CheckRpcSendOk(kNumRpcsPerAddress * num_backends_);
@@ -863,13 +890,22 @@ TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) {
TEST_F(SingleBalancerTest, Drop) {
const size_t kNumRpcsPerAddress = 100;
+ const int num_of_drop_by_rate_limiting_addresses = 1;
+ const int num_of_drop_by_load_balancing_addresses = 2;
+ const int num_of_drop_addresses = num_of_drop_by_rate_limiting_addresses +
+ num_of_drop_by_load_balancing_addresses;
+ const int num_total_addresses = num_backends_ + num_of_drop_addresses;
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(
- GetBackendPorts(), {{"rate_limiting", 1}, {"load_balancing", 2}}),
+ GetBackendPorts(),
+ {{"rate_limiting", num_of_drop_by_rate_limiting_addresses},
+ {"load_balancing", num_of_drop_by_load_balancing_addresses}}),
0);
+ // Wait until all backends are ready.
+ WaitForAllBackends();
// Send kNumRpcsPerAddress RPCs for each server and drop address.
size_t num_drops = 0;
- for (size_t i = 0; i < kNumRpcsPerAddress * (num_backends_ + 3); ++i) {
+ for (size_t i = 0; i < kNumRpcsPerAddress * num_total_addresses; ++i) {
EchoResponse response;
const Status status = SendRpc(&response);
if (!status.ok() &&
@@ -881,7 +917,7 @@ TEST_F(SingleBalancerTest, Drop) {
EXPECT_EQ(response.message(), kMessage_);
}
}
- EXPECT_EQ(kNumRpcsPerAddress * 3, num_drops);
+ EXPECT_EQ(kNumRpcsPerAddress * num_of_drop_addresses, num_drops);
// Each backend should have gotten 100 requests.
for (size_t i = 0; i < backends_.size(); ++i) {
@@ -896,9 +932,12 @@ TEST_F(SingleBalancerTest, Drop) {
TEST_F(SingleBalancerTest, DropAllFirst) {
// All registered addresses are marked as "drop".
+ const int num_of_drop_by_rate_limiting_addresses = 1;
+ const int num_of_drop_by_load_balancing_addresses = 1;
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(
- {}, {{"rate_limiting", 1}, {"load_balancing", 1}}),
+ {}, {{"rate_limiting", num_of_drop_by_rate_limiting_addresses},
+ {"load_balancing", num_of_drop_by_load_balancing_addresses}}),
0);
const Status status = SendRpc();
EXPECT_FALSE(status.ok());
@@ -909,9 +948,12 @@ TEST_F(SingleBalancerTest, DropAll) {
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}),
0);
+ const int num_of_drop_by_rate_limiting_addresses = 1;
+ const int num_of_drop_by_load_balancing_addresses = 1;
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(
- {}, {{"rate_limiting", 1}, {"load_balancing", 1}}),
+ {}, {{"rate_limiting", num_of_drop_by_rate_limiting_addresses},
+ {"load_balancing", num_of_drop_by_load_balancing_addresses}}),
1000);
// First call succeeds.
@@ -936,6 +978,11 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) {
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(GetBackendPorts(), {}),
0);
+ // Wait until all backends are ready.
+ int num_ok = 0;
+ int num_failure = 0;
+ int num_drops = 0;
+ std::tie(num_ok, num_failure, num_drops) = WaitForAllBackends();
// Send kNumRpcsPerAddress RPCs per server.
CheckRpcSendOk(kNumRpcsPerAddress * num_backends_);
// Each backend should have gotten 100 requests.
@@ -950,24 +997,39 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) {
EXPECT_EQ(1U, balancer_servers_[0].service_->response_count());
const ClientStats client_stats = WaitForLoadReports();
- EXPECT_EQ(kNumRpcsPerAddress * num_backends_, client_stats.num_calls_started);
- EXPECT_EQ(kNumRpcsPerAddress * num_backends_,
+ EXPECT_EQ(kNumRpcsPerAddress * num_backends_ + num_ok,
+ client_stats.num_calls_started);
+ EXPECT_EQ(kNumRpcsPerAddress * num_backends_ + num_ok,
client_stats.num_calls_finished);
EXPECT_EQ(0U, client_stats.num_calls_finished_with_client_failed_to_send);
- EXPECT_EQ(kNumRpcsPerAddress * num_backends_,
+ EXPECT_EQ(kNumRpcsPerAddress * num_backends_ + (num_ok + num_drops),
client_stats.num_calls_finished_known_received);
EXPECT_THAT(client_stats.drop_token_counts, ::testing::ElementsAre());
}
TEST_F(SingleBalancerWithClientLoadReportingTest, Drop) {
const size_t kNumRpcsPerAddress = 3;
+ const int num_of_drop_by_rate_limiting_addresses = 2;
+ const int num_of_drop_by_load_balancing_addresses = 1;
+ const int num_of_drop_addresses = num_of_drop_by_rate_limiting_addresses +
+ num_of_drop_by_load_balancing_addresses;
+ const int num_total_addresses = num_backends_ + num_of_drop_addresses;
ScheduleResponseForBalancer(
0, BalancerServiceImpl::BuildResponseForBackends(
- GetBackendPorts(), {{"rate_limiting", 2}, {"load_balancing", 1}}),
+ GetBackendPorts(),
+ {{"rate_limiting", num_of_drop_by_rate_limiting_addresses},
+ {"load_balancing", num_of_drop_by_load_balancing_addresses}}),
0);
-
+ // Wait until all backends are ready.
+ int num_warmup_ok = 0;
+ int num_warmup_failure = 0;
+ int num_warmup_drops = 0;
+ std::tie(num_warmup_ok, num_warmup_failure, num_warmup_drops) =
+ WaitForAllBackends(num_total_addresses /* num_requests_multiple_of */);
+ const int num_total_warmup_requests =
+ num_warmup_ok + num_warmup_failure + num_warmup_drops;
size_t num_drops = 0;
- for (size_t i = 0; i < kNumRpcsPerAddress * (num_backends_ + 3); ++i) {
+ for (size_t i = 0; i < kNumRpcsPerAddress * num_total_addresses; ++i) {
EchoResponse response;
const Status status = SendRpc(&response);
if (!status.ok() &&
@@ -979,8 +1041,7 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Drop) {
EXPECT_EQ(response.message(), kMessage_);
}
}
- EXPECT_EQ(kNumRpcsPerAddress * 3, num_drops);
-
+ EXPECT_EQ(kNumRpcsPerAddress * num_of_drop_addresses, num_drops);
// Each backend should have gotten 100 requests.
for (size_t i = 0; i < backends_.size(); ++i) {
EXPECT_EQ(kNumRpcsPerAddress,
@@ -993,17 +1054,28 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Drop) {
EXPECT_EQ(1U, balancer_servers_[0].service_->response_count());
const ClientStats client_stats = WaitForLoadReports();
- EXPECT_EQ(kNumRpcsPerAddress * (num_backends_ + 3),
- client_stats.num_calls_started);
- EXPECT_EQ(kNumRpcsPerAddress * (num_backends_ + 3),
- client_stats.num_calls_finished);
+ EXPECT_EQ(
+ kNumRpcsPerAddress * num_total_addresses + num_total_warmup_requests,
+ client_stats.num_calls_started);
+ EXPECT_EQ(
+ kNumRpcsPerAddress * num_total_addresses + num_total_warmup_requests,
+ client_stats.num_calls_finished);
EXPECT_EQ(0U, client_stats.num_calls_finished_with_client_failed_to_send);
- EXPECT_EQ(kNumRpcsPerAddress * num_backends_,
+ EXPECT_EQ(kNumRpcsPerAddress * num_backends_ + num_warmup_ok,
client_stats.num_calls_finished_known_received);
- EXPECT_THAT(client_stats.drop_token_counts,
- ::testing::ElementsAre(
- ::testing::Pair("load_balancing", kNumRpcsPerAddress),
- ::testing::Pair("rate_limiting", kNumRpcsPerAddress * 2)));
+ // The number of warmup request is a multiple of the number of addresses.
+ // Therefore, all addresses in the scheduled balancer response are hit the
+ // same number of times.
+ const int num_times_drop_addresses_hit =
+ num_warmup_drops / num_of_drop_addresses;
+ EXPECT_THAT(
+ client_stats.drop_token_counts,
+ ::testing::ElementsAre(
+ ::testing::Pair("load_balancing",
+ (kNumRpcsPerAddress + num_times_drop_addresses_hit)),
+ ::testing::Pair(
+ "rate_limiting",
+ (kNumRpcsPerAddress + num_times_drop_addresses_hit) * 2)));
}
} // namespace
diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD
index 985a335f1b..0b69e9ba9a 100644
--- a/test/cpp/microbenchmarks/BUILD
+++ b/test/cpp/microbenchmarks/BUILD
@@ -73,12 +73,29 @@ grpc_cc_binary(
deps = [":helpers"],
)
+grpc_cc_library(
+ name = "fullstack_streaming_ping_pong_h",
+ testonly = 1,
+ hdrs = [
+ "fullstack_streaming_ping_pong.h",
+ ],
+ deps = [":helpers"],
+)
+
grpc_cc_binary(
name = "bm_fullstack_streaming_ping_pong",
testonly = 1,
srcs = [
"bm_fullstack_streaming_ping_pong.cc",
- "fullstack_streaming_ping_pong.h",
+ ],
+ deps = [":fullstack_streaming_ping_pong_h"],
+)
+
+grpc_cc_library(
+ name = "fullstack_streaming_pump_h",
+ testonly = 1,
+ hdrs = [
+ "fullstack_streaming_pump.h",
],
deps = [":helpers"],
)
@@ -88,9 +105,8 @@ grpc_cc_binary(
testonly = 1,
srcs = [
"bm_fullstack_streaming_pump.cc",
- "fullstack_streaming_pump.h",
],
- deps = [":helpers"],
+ deps = [":fullstack_streaming_pump_h"],
)
grpc_cc_binary(
@@ -103,14 +119,22 @@ grpc_cc_binary(
],
)
+grpc_cc_library(
+ name = "fullstack_unary_ping_pong_h",
+ testonly = 1,
+ hdrs = [
+ "fullstack_unary_ping_pong.h",
+ ],
+ deps = [":helpers"],
+)
+
grpc_cc_binary(
name = "bm_fullstack_unary_ping_pong",
testonly = 1,
srcs = [
"bm_fullstack_unary_ping_pong.cc",
- "fullstack_unary_ping_pong.h",
],
- deps = [":helpers"],
+ deps = [":fullstack_unary_ping_pong_h"],
)
grpc_cc_binary(
diff --git a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
index 9d71d3990d..5c9405f583 100644
--- a/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
+++ b/test/cpp/microbenchmarks/bm_cq_multiple_threads.cc
@@ -59,7 +59,8 @@ static void pollset_destroy(grpc_exec_ctx* exec_ctx, grpc_pollset* ps) {
gpr_mu_destroy(&ps->mu);
}
-static grpc_error* pollset_kick(grpc_pollset* p, grpc_pollset_worker* worker) {
+static grpc_error* pollset_kick(grpc_exec_ctx* exec_ctx, grpc_pollset* p,
+ grpc_pollset_worker* worker) {
return GRPC_ERROR_NONE;
}
diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
index 59fb29dd60..2656566a50 100644
--- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
+++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc
@@ -22,7 +22,6 @@
#include <gflags/gflags.h>
#include <fstream>
#include "src/core/lib/profiling/timers.h"
-#include "src/cpp/client/create_channel_internal.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h
index 5477b860b4..ecd28c3f8a 100644
--- a/test/cpp/microbenchmarks/fullstack_fixtures.h
+++ b/test/cpp/microbenchmarks/fullstack_fixtures.h
@@ -41,6 +41,7 @@ extern "C" {
#include "test/core/util/port.h"
}
+#include "src/cpp/client/create_channel_internal.h"
#include "test/cpp/microbenchmarks/helpers.h"
namespace grpc {
diff --git a/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h b/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h
index ff1f966753..6df044f344 100644
--- a/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h
+++ b/test/cpp/microbenchmarks/fullstack_streaming_ping_pong.h
@@ -24,7 +24,6 @@
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
-#include "src/cpp/client/create_channel_internal.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
diff --git a/test/cpp/microbenchmarks/fullstack_streaming_pump.h b/test/cpp/microbenchmarks/fullstack_streaming_pump.h
index f9db212b02..9e826091ec 100644
--- a/test/cpp/microbenchmarks/fullstack_streaming_pump.h
+++ b/test/cpp/microbenchmarks/fullstack_streaming_pump.h
@@ -24,7 +24,6 @@
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
-#include "src/cpp/client/create_channel_internal.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
diff --git a/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h b/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h
index 76d278b2a0..d448938295 100644
--- a/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h
+++ b/test/cpp/microbenchmarks/fullstack_unary_ping_pong.h
@@ -24,7 +24,6 @@
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
-#include "src/cpp/client/create_channel_internal.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
diff --git a/test/cpp/naming/BUILD b/test/cpp/naming/BUILD
new file mode 100644
index 0000000000..24c3d1a443
--- /dev/null
+++ b/test/cpp/naming/BUILD
@@ -0,0 +1,49 @@
+# Copyright 2017 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+package(
+ default_visibility = ["//visibility:public"],
+ features = [
+ "-layering_check",
+ "-parse_headers",
+ ],
+)
+
+licenses(["notice"]) # Apache v2
+
+load("//bazel:grpc_build_system.bzl", "grpc_sh_binary", "grpc_py_binary")
+
+load(":generate_resolver_component_tests.bzl", "generate_resolver_component_tests")
+
+# Meant to be invoked only through the top-level shell script driver.
+grpc_sh_binary(
+ name = "resolver_component_tests_runner",
+ srcs = [
+ "resolver_component_tests_runner.sh",
+ ],
+)
+
+grpc_py_binary(
+ name = "test_dns_server",
+ srcs = ["test_dns_server.py"],
+ data = [
+ "resolver_test_record_groups.yaml",
+ ],
+ deps = [
+ "twisted",
+ "yaml",
+ ]
+)
+
+generate_resolver_component_tests()
diff --git a/test/cpp/naming/gen_build_yaml.py b/test/cpp/naming/gen_build_yaml.py
new file mode 100755
index 0000000000..3a51fef7a0
--- /dev/null
+++ b/test/cpp/naming/gen_build_yaml.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python2.7
+# Copyright 2015 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""Generates the appropriate build.json data for all the naming tests."""
+
+
+import yaml
+import collections
+import hashlib
+import json
+
+_LOCAL_DNS_SERVER_ADDRESS = '127.0.0.1:15353'
+
+def _append_zone_name(name, zone_name):
+ return '%s.%s' % (name, zone_name)
+
+def _build_expected_addrs_cmd_arg(expected_addrs):
+ out = []
+ for addr in expected_addrs:
+ out.append('%s,%s' % (addr['address'], str(addr['is_balancer'])))
+ return ';'.join(out)
+
+def main():
+ resolver_component_data = ''
+ with open('test/cpp/naming/resolver_test_record_groups.yaml') as f:
+ resolver_component_data = yaml.load(f)
+
+ json = {
+ 'resolver_component_test_cases': [
+ {
+ 'target_name': _append_zone_name(test_case['record_to_resolve'],
+ resolver_component_data['resolver_component_tests_common_zone_name']),
+ 'expected_addrs': _build_expected_addrs_cmd_arg(test_case['expected_addrs']),
+ 'expected_chosen_service_config': (test_case['expected_chosen_service_config'] or ''),
+ 'expected_lb_policy': (test_case['expected_lb_policy'] or ''),
+ } for test_case in resolver_component_data['resolver_component_tests']
+ ],
+ 'targets': [
+ {
+ 'name': 'resolver_component_test' + unsecure_build_config_suffix,
+ 'build': 'test',
+ 'language': 'c++',
+ 'gtest': False,
+ 'run': False,
+ 'src': ['test/cpp/naming/resolver_component_test.cc'],
+ 'platforms': ['linux', 'posix', 'mac'],
+ 'deps': [
+ 'grpc++_test_util' + unsecure_build_config_suffix,
+ 'grpc_test_util' + unsecure_build_config_suffix,
+ 'gpr_test_util',
+ 'grpc++' + unsecure_build_config_suffix,
+ 'grpc' + unsecure_build_config_suffix,
+ 'gpr',
+ 'grpc++_test_config',
+ ],
+ } for unsecure_build_config_suffix in ['_unsecure', '']
+ ] + [
+ {
+ 'name': 'resolver_component_tests_runner_invoker' + unsecure_build_config_suffix,
+ 'build': 'test',
+ 'language': 'c++',
+ 'gtest': False,
+ 'run': True,
+ 'src': ['test/cpp/naming/resolver_component_tests_runner_invoker.cc'],
+ 'platforms': ['linux', 'posix', 'mac'],
+ 'deps': [
+ 'grpc++_test_util',
+ 'grpc_test_util',
+ 'gpr_test_util',
+ 'grpc++',
+ 'grpc',
+ 'gpr',
+ 'grpc++_test_config',
+ ],
+ 'args': [
+ '--test_bin_name=resolver_component_test%s' % unsecure_build_config_suffix,
+ '--running_under_bazel=false',
+ ],
+ } for unsecure_build_config_suffix in ['_unsecure', '']
+ ]
+ }
+
+ print(yaml.dump(json))
+
+if __name__ == '__main__':
+ main()
diff --git a/test/cpp/naming/generate_resolver_component_tests.bzl b/test/cpp/naming/generate_resolver_component_tests.bzl
new file mode 100755
index 0000000000..118d9452d9
--- /dev/null
+++ b/test/cpp/naming/generate_resolver_component_tests.bzl
@@ -0,0 +1,64 @@
+#!/usr/bin/env python2.7
+# Copyright 2015 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//bazel:grpc_build_system.bzl", "grpc_sh_binary", "grpc_cc_test", "grpc_cc_binary")
+
+def generate_resolver_component_tests():
+ for unsecure_build_config_suffix in ['_unsecure', '']:
+ # meant to be invoked only through the top-level shell script driver
+ grpc_cc_binary(
+ name = "resolver_component_test%s" % unsecure_build_config_suffix,
+ testonly = 1,
+ srcs = [
+ "resolver_component_test.cc",
+ ],
+ external_deps = [
+ "gmock",
+ ],
+ deps = [
+ "//test/cpp/util:test_util%s" % unsecure_build_config_suffix,
+ "//test/core/util:grpc_test_util%s" % unsecure_build_config_suffix,
+ "//test/core/util:gpr_test_util",
+ "//:grpc++%s" % unsecure_build_config_suffix,
+ "//:grpc%s" % unsecure_build_config_suffix,
+ "//:gpr",
+ "//test/cpp/util:test_config",
+ ],
+ )
+ grpc_cc_test(
+ name = "resolver_component_tests_runner_invoker%s" % unsecure_build_config_suffix,
+ srcs = [
+ "resolver_component_tests_runner_invoker.cc",
+ ],
+ deps = [
+ "//test/cpp/util:test_util",
+ "//test/core/util:grpc_test_util",
+ "//test/core/util:gpr_test_util",
+ "//:grpc++",
+ "//:grpc",
+ "//:gpr",
+ "//test/cpp/util:test_config",
+ ],
+ data = [
+ ":resolver_component_tests_runner",
+ ":resolver_component_test%s" % unsecure_build_config_suffix,
+ ":test_dns_server",
+ "resolver_test_record_groups.yaml", # include the transitive dependency so that the dns sever py binary can locate this
+ ],
+ args = [
+ "--test_bin_name=resolver_component_test%s" % unsecure_build_config_suffix,
+ "--running_under_bazel=true",
+ ]
+ )
diff --git a/test/cpp/naming/resolver_component_test.cc b/test/cpp/naming/resolver_component_test.cc
new file mode 100644
index 0000000000..cc851ca9d5
--- /dev/null
+++ b/test/cpp/naming/resolver_component_test.cc
@@ -0,0 +1,326 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/host_port.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <grpc/support/sync.h>
+#include <grpc/support/time.h>
+#include <string.h>
+
+#include <gflags/gflags.h>
+#include <gmock/gmock.h>
+#include <vector>
+
+#include "test/cpp/util/subprocess.h"
+#include "test/cpp/util/test_config.h"
+
+extern "C" {
+#include "src/core/ext/filters/client_channel/client_channel.h"
+#include "src/core/ext/filters/client_channel/resolver.h"
+#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
+#include "src/core/ext/filters/client_channel/resolver_registry.h"
+#include "src/core/lib/channel/channel_args.h"
+#include "src/core/lib/iomgr/combiner.h"
+#include "src/core/lib/iomgr/executor.h"
+#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/resolve_address.h"
+#include "src/core/lib/iomgr/sockaddr_utils.h"
+#include "src/core/lib/support/env.h"
+#include "src/core/lib/support/string.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+}
+
+using std::vector;
+using grpc::SubProcess;
+using testing::UnorderedElementsAreArray;
+
+// Hack copied from "test/cpp/end2end/server_crash_test_client.cc"!
+// In some distros, gflags is in the namespace google, and in some others,
+// in gflags. This hack is enabling us to find both.
+namespace google {}
+namespace gflags {}
+using namespace google;
+using namespace gflags;
+
+DEFINE_string(target_name, "", "Target name to resolve.");
+DEFINE_string(expected_addrs, "",
+ "Comma-separated list of expected "
+ "'<ip0:port0>,<is_balancer0>;<ip1:port1>,<is_balancer1>;...' "
+ "addresses of "
+ "backend and/or balancers. 'is_balancer' should be bool, i.e. "
+ "true or false.");
+DEFINE_string(expected_chosen_service_config, "",
+ "Expected service config json string that gets chosen (no "
+ "whitespace). Empty for none.");
+DEFINE_string(
+ local_dns_server_address, "",
+ "Optional. This address is placed as the uri authority if present.");
+DEFINE_string(expected_lb_policy, "",
+ "Expected lb policy name that appears in resolver result channel "
+ "arg. Empty for none.");
+
+namespace {
+
+class GrpcLBAddress final {
+ public:
+ GrpcLBAddress(std::string address, bool is_balancer)
+ : is_balancer(is_balancer), address(address) {}
+
+ bool operator==(const GrpcLBAddress &other) const {
+ return this->is_balancer == other.is_balancer &&
+ this->address == other.address;
+ }
+
+ bool operator!=(const GrpcLBAddress &other) const {
+ return !(*this == other);
+ }
+
+ bool is_balancer;
+ std::string address;
+};
+
+vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
+ std::vector<GrpcLBAddress> out;
+ while (expected_addrs.size() != 0) {
+ // get the next <ip>,<port> (v4 or v6)
+ size_t next_comma = expected_addrs.find(",");
+ if (next_comma == std::string::npos) {
+ gpr_log(
+ GPR_ERROR,
+ "Missing ','. Expected_addrs arg should be a semi-colon-separated "
+ "list of "
+ "<ip-port>,<bool> pairs. Left-to-be-parsed arg is |%s|",
+ expected_addrs.c_str());
+ abort();
+ }
+ std::string next_addr = expected_addrs.substr(0, next_comma);
+ expected_addrs = expected_addrs.substr(next_comma + 1, std::string::npos);
+ // get the next is_balancer 'bool' associated with this address
+ size_t next_semicolon = expected_addrs.find(";");
+ bool is_balancer =
+ gpr_is_true(expected_addrs.substr(0, next_semicolon).c_str());
+ out.emplace_back(GrpcLBAddress(next_addr, is_balancer));
+ if (next_semicolon == std::string::npos) {
+ break;
+ }
+ expected_addrs =
+ expected_addrs.substr(next_semicolon + 1, std::string::npos);
+ }
+ if (out.size() == 0) {
+ gpr_log(GPR_ERROR,
+ "expected_addrs arg should be a comma-separated list of "
+ "<ip-port>,<bool> pairs");
+ abort();
+ }
+ return out;
+}
+
+gpr_timespec TestDeadline(void) {
+ return grpc_timeout_seconds_to_deadline(100);
+}
+
+struct ArgsStruct {
+ gpr_event ev;
+ gpr_atm done_atm;
+ gpr_mu *mu;
+ grpc_pollset *pollset;
+ grpc_pollset_set *pollset_set;
+ grpc_combiner *lock;
+ grpc_channel_args *channel_args;
+ vector<GrpcLBAddress> expected_addrs;
+ std::string expected_service_config_string;
+ std::string expected_lb_policy;
+};
+
+void ArgsInit(grpc_exec_ctx *exec_ctx, ArgsStruct *args) {
+ gpr_event_init(&args->ev);
+ args->pollset = (grpc_pollset *)gpr_zalloc(grpc_pollset_size());
+ grpc_pollset_init(args->pollset, &args->mu);
+ args->pollset_set = grpc_pollset_set_create();
+ grpc_pollset_set_add_pollset(exec_ctx, args->pollset_set, args->pollset);
+ args->lock = grpc_combiner_create();
+ gpr_atm_rel_store(&args->done_atm, 0);
+ args->channel_args = NULL;
+}
+
+void DoNothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {}
+
+void ArgsFinish(grpc_exec_ctx *exec_ctx, ArgsStruct *args) {
+ GPR_ASSERT(gpr_event_wait(&args->ev, TestDeadline()));
+ grpc_pollset_set_del_pollset(exec_ctx, args->pollset_set, args->pollset);
+ grpc_pollset_set_destroy(exec_ctx, args->pollset_set);
+ grpc_closure DoNothing_cb;
+ GRPC_CLOSURE_INIT(&DoNothing_cb, DoNothing, NULL, grpc_schedule_on_exec_ctx);
+ grpc_pollset_shutdown(exec_ctx, args->pollset, &DoNothing_cb);
+ // exec_ctx needs to be flushed before calling grpc_pollset_destroy()
+ grpc_channel_args_destroy(exec_ctx, args->channel_args);
+ grpc_exec_ctx_flush(exec_ctx);
+ grpc_pollset_destroy(exec_ctx, args->pollset);
+ gpr_free(args->pollset);
+ GRPC_COMBINER_UNREF(exec_ctx, args->lock, NULL);
+}
+
+gpr_timespec NSecondDeadline(int seconds) {
+ return gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(seconds, GPR_TIMESPAN));
+}
+
+void PollPollsetUntilRequestDone(ArgsStruct *args) {
+ gpr_timespec deadline = NSecondDeadline(10);
+ while (true) {
+ bool done = gpr_atm_acq_load(&args->done_atm) != 0;
+ if (done) {
+ break;
+ }
+ gpr_timespec time_left =
+ gpr_time_sub(deadline, gpr_now(GPR_CLOCK_REALTIME));
+ gpr_log(GPR_DEBUG, "done=%d, time_left=%" PRId64 ".%09d", done,
+ time_left.tv_sec, time_left.tv_nsec);
+ GPR_ASSERT(gpr_time_cmp(time_left, gpr_time_0(GPR_TIMESPAN)) >= 0);
+ grpc_pollset_worker *worker = NULL;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ gpr_mu_lock(args->mu);
+ GRPC_LOG_IF_ERROR(
+ "pollset_work",
+ grpc_pollset_work(&exec_ctx, args->pollset, &worker,
+ gpr_now(GPR_CLOCK_REALTIME), NSecondDeadline(1)));
+ gpr_mu_unlock(args->mu);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ gpr_event_set(&args->ev, (void *)1);
+}
+
+void CheckServiceConfigResultLocked(grpc_channel_args *channel_args,
+ ArgsStruct *args) {
+ const grpc_arg *service_config_arg =
+ grpc_channel_args_find(channel_args, GRPC_ARG_SERVICE_CONFIG);
+ if (args->expected_service_config_string != "") {
+ GPR_ASSERT(service_config_arg != NULL);
+ GPR_ASSERT(service_config_arg->type == GRPC_ARG_STRING);
+ EXPECT_EQ(service_config_arg->value.string,
+ args->expected_service_config_string);
+ } else {
+ GPR_ASSERT(service_config_arg == NULL);
+ }
+}
+
+void CheckLBPolicyResultLocked(grpc_channel_args *channel_args,
+ ArgsStruct *args) {
+ const grpc_arg *lb_policy_arg =
+ grpc_channel_args_find(channel_args, GRPC_ARG_LB_POLICY_NAME);
+ if (args->expected_lb_policy != "") {
+ GPR_ASSERT(lb_policy_arg != NULL);
+ GPR_ASSERT(lb_policy_arg->type == GRPC_ARG_STRING);
+ EXPECT_EQ(lb_policy_arg->value.string, args->expected_lb_policy);
+ } else {
+ GPR_ASSERT(lb_policy_arg == NULL);
+ }
+}
+
+void CheckResolverResultLocked(grpc_exec_ctx *exec_ctx, void *argsp,
+ grpc_error *err) {
+ ArgsStruct *args = (ArgsStruct *)argsp;
+ grpc_channel_args *channel_args = args->channel_args;
+ const grpc_arg *channel_arg =
+ grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES);
+ GPR_ASSERT(channel_arg != NULL);
+ GPR_ASSERT(channel_arg->type == GRPC_ARG_POINTER);
+ grpc_lb_addresses *addresses =
+ (grpc_lb_addresses *)channel_arg->value.pointer.p;
+ gpr_log(GPR_INFO, "num addrs found: %" PRIdPTR ". expected %" PRIdPTR,
+ addresses->num_addresses, args->expected_addrs.size());
+ GPR_ASSERT(addresses->num_addresses == args->expected_addrs.size());
+ std::vector<GrpcLBAddress> found_lb_addrs;
+ for (size_t i = 0; i < addresses->num_addresses; i++) {
+ grpc_lb_address addr = addresses->addresses[i];
+ char *str;
+ grpc_sockaddr_to_string(&str, &addr.address, 1 /* normalize */);
+ gpr_log(GPR_INFO, "%s", str);
+ found_lb_addrs.emplace_back(
+ GrpcLBAddress(std::string(str), addr.is_balancer));
+ gpr_free(str);
+ }
+ if (args->expected_addrs.size() != found_lb_addrs.size()) {
+ gpr_log(GPR_DEBUG, "found lb addrs size is: %" PRIdPTR
+ ". expected addrs size is %" PRIdPTR,
+ found_lb_addrs.size(), args->expected_addrs.size());
+ abort();
+ }
+ EXPECT_THAT(args->expected_addrs, UnorderedElementsAreArray(found_lb_addrs));
+ CheckServiceConfigResultLocked(channel_args, args);
+ if (args->expected_service_config_string == "") {
+ CheckLBPolicyResultLocked(channel_args, args);
+ }
+ gpr_atm_rel_store(&args->done_atm, 1);
+ gpr_mu_lock(args->mu);
+ GRPC_LOG_IF_ERROR("pollset_kick",
+ grpc_pollset_kick(exec_ctx, args->pollset, NULL));
+ gpr_mu_unlock(args->mu);
+}
+
+TEST(ResolverComponentTest, TestResolvesRelevantRecords) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ ArgsStruct args;
+ ArgsInit(&exec_ctx, &args);
+ args.expected_addrs = ParseExpectedAddrs(FLAGS_expected_addrs);
+ args.expected_service_config_string = FLAGS_expected_chosen_service_config;
+ args.expected_lb_policy = FLAGS_expected_lb_policy;
+ // maybe build the address with an authority
+ char *whole_uri = NULL;
+ GPR_ASSERT(asprintf(&whole_uri, "dns://%s/%s",
+ FLAGS_local_dns_server_address.c_str(),
+ FLAGS_target_name.c_str()));
+ // create resolver and resolve
+ grpc_resolver *resolver = grpc_resolver_create(&exec_ctx, whole_uri, NULL,
+ args.pollset_set, args.lock);
+ gpr_free(whole_uri);
+ grpc_closure on_resolver_result_changed;
+ GRPC_CLOSURE_INIT(&on_resolver_result_changed, CheckResolverResultLocked,
+ (void *)&args, grpc_combiner_scheduler(args.lock));
+ grpc_resolver_next_locked(&exec_ctx, resolver, &args.channel_args,
+ &on_resolver_result_changed);
+ grpc_exec_ctx_flush(&exec_ctx);
+ PollPollsetUntilRequestDone(&args);
+ GRPC_RESOLVER_UNREF(&exec_ctx, resolver, NULL);
+ ArgsFinish(&exec_ctx, &args);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
+} // namespace
+
+int main(int argc, char **argv) {
+ grpc_init();
+ grpc_test_init(argc, argv);
+ ::testing::InitGoogleTest(&argc, argv);
+ ParseCommandLineFlags(&argc, &argv, true);
+ if (FLAGS_target_name == "") {
+ gpr_log(GPR_ERROR, "Missing target_name param.");
+ abort();
+ }
+ if (FLAGS_local_dns_server_address != "") {
+ gpr_log(GPR_INFO, "Specifying authority in uris to: %s",
+ FLAGS_local_dns_server_address.c_str());
+ }
+ auto result = RUN_ALL_TESTS();
+ grpc_shutdown();
+ return result;
+}
diff --git a/test/cpp/naming/resolver_component_tests_runner.sh b/test/cpp/naming/resolver_component_tests_runner.sh
new file mode 100755
index 0000000000..cf71c9dcf9
--- /dev/null
+++ b/test/cpp/naming/resolver_component_tests_runner.sh
@@ -0,0 +1,181 @@
+#!/bin/bash
+# Copyright 2015 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This file is auto-generated
+
+set -ex
+
+# all command args required in this set order
+FLAGS_test_bin_path=`echo "$1" | grep '\--test_bin_path=' | cut -d "=" -f 2`
+FLAGS_dns_server_bin_path=`echo "$2" | grep '\--dns_server_bin_path=' | cut -d "=" -f 2`
+FLAGS_records_config_path=`echo "$3" | grep '\--records_config_path=' | cut -d "=" -f 2`
+FLAGS_test_dns_server_port=`echo "$4" | grep '\--test_dns_server_port=' | cut -d "=" -f 2`
+
+for cmd_arg in "$FLAGS_test_bin_path" "$FLAGS_dns_server_bin_path" "$FLAGS_records_config_path" "$FLAGS_test_dns_server_port"; do
+ if [[ "$cmd_arg" == "" ]]; then
+ echo "Missing a CMD arg" && exit 1
+ fi
+done
+
+if [[ "$GRPC_DNS_RESOLVER" != "" && "$GRPC_DNS_RESOLVER" != ares ]]; then
+ echo "This test only works under GRPC_DNS_RESOLVER=ares. Have GRPC_DNS_RESOLVER=$GRPC_DNS_RESOLVER" && exit 1
+fi
+export GRPC_DNS_RESOLVER=ares
+
+"$FLAGS_dns_server_bin_path" --records_config_path="$FLAGS_records_config_path" --port="$FLAGS_test_dns_server_port" 2>&1 > /dev/null &
+DNS_SERVER_PID=$!
+echo "Local DNS server started. PID: $DNS_SERVER_PID"
+
+# Health check local DNS server TCP and UDP ports
+for ((i=0;i<30;i++));
+do
+ echo "Retry health-check DNS query to local DNS server over tcp and udp"
+ RETRY=0
+ dig A health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. @localhost -p "$FLAGS_test_dns_server_port" +tries=1 +timeout=1 | grep '123.123.123.123' || RETRY=1
+ dig A health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp. @localhost -p "$FLAGS_test_dns_server_port" +tries=1 +timeout=1 +tcp | grep '123.123.123.123' || RETRY=1
+ if [[ "$RETRY" == 0 ]]; then
+ break
+ fi;
+ sleep 0.1
+done
+
+if [[ $RETRY == 1 ]]; then
+ echo "FAILED TO START LOCAL DNS SERVER"
+ kill -SIGTERM $DNS_SERVER_PID
+ wait
+ exit 1
+fi
+
+function terminate_all {
+ echo "Received signal. Terminating $! and $DNS_SERVER_PID"
+ kill -SIGTERM $! || true
+ kill -SIGTERM $DNS_SERVER_PID || true
+ wait
+ exit 1
+}
+
+trap terminate_all SIGTERM SIGINT
+
+EXIT_CODE=0
+# TODO: this test should check for GCE residency and skip tests using _grpclb._tcp.* SRV records once GCE residency checks are made
+# in the resolver.
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv4-single-target.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:1234,True' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv4-multi-target.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.5:1234,True;1.2.3.6:1234,True;1.2.3.7:1234,True' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv6-single-target.resolver-tests.grpctestingexp.' \
+ --expected_addrs='[2607:f8b0:400a:801::1001]:1234,True' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv6-multi-target.resolver-tests.grpctestingexp.' \
+ --expected_addrs='[2607:f8b0:400a:801::1002]:1234,True;[2607:f8b0:400a:801::1003]:1234,True;[2607:f8b0:400a:801::1004]:1234,True' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv4-simple-service-config.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:1234,True' \
+ --expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]}]}' \
+ --expected_lb_policy='round_robin' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-no-srv-simple-service-config.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"NoSrvSimpleService","waitForReady":true}]}]}' \
+ --expected_lb_policy='round_robin' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-no-config-for-cpp.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-cpp-config-has-zero-percentage.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-second-language-is-cpp.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"CppService","waitForReady":true}]}]}' \
+ --expected_lb_policy='round_robin' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-config-with-percentages.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"AlwaysPickedService","waitForReady":true}]}]}' \
+ --expected_lb_policy='round_robin' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv4-target-has-backend-and-balancer.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:1234,True;1.2.3.4:443,False' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='srv-ipv6-target-has-backend-and-balancer.resolver-tests.grpctestingexp.' \
+ --expected_addrs='[2607:f8b0:400a:801::1002]:1234,True;[2607:f8b0:400a:801::1002]:443,False' \
+ --expected_chosen_service_config='' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+$FLAGS_test_bin_path \
+ --target_name='ipv4-config-causing-fallback-to-tcp.resolver-tests.grpctestingexp.' \
+ --expected_addrs='1.2.3.4:443,False' \
+ --expected_chosen_service_config='{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooThree","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFour","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFive","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSix","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSeven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEight","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooNine","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTen","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEleven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]}]}' \
+ --expected_lb_policy='' \
+ --local_dns_server_address=127.0.0.1:$FLAGS_test_dns_server_port &
+wait $! || EXIT_CODE=1
+
+kill -SIGTERM $DNS_SERVER_PID || true
+wait
+exit $EXIT_CODE
diff --git a/test/cpp/naming/resolver_component_tests_runner_invoker.cc b/test/cpp/naming/resolver_component_tests_runner_invoker.cc
new file mode 100644
index 0000000000..b14391284d
--- /dev/null
+++ b/test/cpp/naming/resolver_component_tests_runner_invoker.cc
@@ -0,0 +1,189 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <gflags/gflags.h>
+#include <string>
+#include <thread>
+#include <vector>
+
+#include "test/cpp/util/subprocess.h"
+#include "test/cpp/util/test_config.h"
+
+extern "C" {
+#include "src/core/lib/support/env.h"
+#include "test/core/util/port.h"
+}
+
+DEFINE_bool(
+ running_under_bazel, false,
+ "True if this test is running under bazel. "
+ "False indicates that this test is running under run_tests.py. "
+ "Child process test binaries are located differently based on this flag. ");
+
+DEFINE_string(test_bin_name, "",
+ "Name, without the preceding path, of the test binary");
+
+DEFINE_string(grpc_test_directory_relative_to_test_srcdir, "/__main__",
+ "This flag only applies if runner_under_bazel is true. This "
+ "flag is ignored if runner_under_bazel is false. "
+ "Directory of the <repo-root>/test directory relative to bazel's "
+ "TEST_SRCDIR environment variable");
+
+using grpc::SubProcess;
+
+static volatile sig_atomic_t abort_wait_for_child = 0;
+
+static void sighandler(int sig) { abort_wait_for_child = 1; }
+
+static void register_sighandler() {
+ struct sigaction act;
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = sighandler;
+ sigaction(SIGINT, &act, NULL);
+ sigaction(SIGTERM, &act, NULL);
+}
+
+namespace {
+
+const int kTestTimeoutSeconds = 60 * 2;
+
+void RunSigHandlingThread(SubProcess *test_driver, gpr_mu *test_driver_mu,
+ gpr_cv *test_driver_cv, int *test_driver_done) {
+ gpr_timespec overall_deadline =
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
+ gpr_time_from_seconds(kTestTimeoutSeconds, GPR_TIMESPAN));
+ while (true) {
+ gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
+ if (gpr_time_cmp(now, overall_deadline) > 0 || abort_wait_for_child) break;
+ gpr_mu_lock(test_driver_mu);
+ if (*test_driver_done) {
+ gpr_mu_unlock(test_driver_mu);
+ return;
+ }
+ gpr_timespec wait_deadline = gpr_time_add(
+ gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(1, GPR_TIMESPAN));
+ gpr_cv_wait(test_driver_cv, test_driver_mu, wait_deadline);
+ gpr_mu_unlock(test_driver_mu);
+ }
+ gpr_log(GPR_DEBUG,
+ "Test timeout reached or received signal. Interrupting test driver "
+ "child process.");
+ test_driver->Interrupt();
+ return;
+}
+}
+
+namespace grpc {
+
+namespace testing {
+
+void InvokeResolverComponentTestsRunner(std::string test_runner_bin_path,
+ std::string test_bin_path,
+ std::string dns_server_bin_path,
+ std::string records_config_path) {
+ int test_dns_server_port = grpc_pick_unused_port_or_die();
+
+ SubProcess *test_driver = new SubProcess(
+ {test_runner_bin_path, "--test_bin_path=" + test_bin_path,
+ "--dns_server_bin_path=" + dns_server_bin_path,
+ "--records_config_path=" + records_config_path,
+ "--test_dns_server_port=" + std::to_string(test_dns_server_port)});
+ gpr_mu test_driver_mu;
+ gpr_mu_init(&test_driver_mu);
+ gpr_cv test_driver_cv;
+ gpr_cv_init(&test_driver_cv);
+ int test_driver_done = 0;
+ register_sighandler();
+ std::thread sig_handling_thread(RunSigHandlingThread, test_driver,
+ &test_driver_mu, &test_driver_cv,
+ &test_driver_done);
+ int status = test_driver->Join();
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status)) {
+ gpr_log(GPR_INFO,
+ "Resolver component test test-runner exited with code %d",
+ WEXITSTATUS(status));
+ abort();
+ }
+ } else if (WIFSIGNALED(status)) {
+ gpr_log(GPR_INFO,
+ "Resolver component test test-runner ended from signal %d",
+ WTERMSIG(status));
+ abort();
+ } else {
+ gpr_log(GPR_INFO,
+ "Resolver component test test-runner ended with unknown status %d",
+ status);
+ abort();
+ }
+ gpr_mu_lock(&test_driver_mu);
+ test_driver_done = 1;
+ gpr_cv_signal(&test_driver_cv);
+ gpr_mu_unlock(&test_driver_mu);
+ sig_handling_thread.join();
+ delete test_driver;
+ gpr_mu_destroy(&test_driver_mu);
+ gpr_cv_destroy(&test_driver_cv);
+}
+
+} // namespace testing
+
+} // namespace grpc
+
+int main(int argc, char **argv) {
+ grpc::testing::InitTest(&argc, &argv, true);
+ grpc_init();
+ GPR_ASSERT(FLAGS_test_bin_name != "");
+ std::string my_bin = argv[0];
+ if (FLAGS_running_under_bazel) {
+ GPR_ASSERT(FLAGS_grpc_test_directory_relative_to_test_srcdir != "");
+ // Use bazel's TEST_SRCDIR environment variable to locate the "test data"
+ // binaries.
+ std::string const bin_dir =
+ gpr_getenv("TEST_SRCDIR") +
+ FLAGS_grpc_test_directory_relative_to_test_srcdir +
+ std::string("/test/cpp/naming");
+ // Invoke bazel's executeable links to the .sh and .py scripts (don't use
+ // the .sh and .py suffixes) to make
+ // sure that we're using bazel's test environment.
+ grpc::testing::InvokeResolverComponentTestsRunner(
+ bin_dir + "/resolver_component_tests_runner",
+ bin_dir + "/" + FLAGS_test_bin_name, bin_dir + "/test_dns_server",
+ bin_dir + "/resolver_test_record_groups.yaml");
+ } else {
+ // Get the current binary's directory relative to repo root to invoke the
+ // correct build config (asan/tsan/dbg, etc.).
+ std::string const bin_dir = my_bin.substr(0, my_bin.rfind('/'));
+ // Invoke the .sh and .py scripts directly where they are in source code.
+ grpc::testing::InvokeResolverComponentTestsRunner(
+ "test/cpp/naming/resolver_component_tests_runner.sh",
+ bin_dir + "/" + FLAGS_test_bin_name,
+ "test/cpp/naming/test_dns_server.py",
+ "test/cpp/naming/resolver_test_record_groups.yaml");
+ }
+ grpc_shutdown();
+ return 0;
+}
diff --git a/test/cpp/naming/resolver_test_record_groups.yaml b/test/cpp/naming/resolver_test_record_groups.yaml
new file mode 100644
index 0000000000..33d774ca70
--- /dev/null
+++ b/test/cpp/naming/resolver_test_record_groups.yaml
@@ -0,0 +1,149 @@
+resolver_component_tests_common_zone_name: resolver-tests.grpctestingexp.
+resolver_component_tests:
+- expected_addrs:
+ - {address: '1.2.3.4:1234', is_balancer: true}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv4-single-target
+ records:
+ _grpclb._tcp.srv-ipv4-single-target:
+ - {TTL: '2100', data: 0 0 1234 ipv4-single-target, type: SRV}
+ ipv4-single-target:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+- expected_addrs:
+ - {address: '1.2.3.5:1234', is_balancer: true}
+ - {address: '1.2.3.6:1234', is_balancer: true}
+ - {address: '1.2.3.7:1234', is_balancer: true}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv4-multi-target
+ records:
+ _grpclb._tcp.srv-ipv4-multi-target:
+ - {TTL: '2100', data: 0 0 1234 ipv4-multi-target, type: SRV}
+ ipv4-multi-target:
+ - {TTL: '2100', data: 1.2.3.5, type: A}
+ - {TTL: '2100', data: 1.2.3.6, type: A}
+ - {TTL: '2100', data: 1.2.3.7, type: A}
+- expected_addrs:
+ - {address: '[2607:f8b0:400a:801::1001]:1234', is_balancer: true}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv6-single-target
+ records:
+ _grpclb._tcp.srv-ipv6-single-target:
+ - {TTL: '2100', data: 0 0 1234 ipv6-single-target, type: SRV}
+ ipv6-single-target:
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1001', type: AAAA}
+- expected_addrs:
+ - {address: '[2607:f8b0:400a:801::1002]:1234', is_balancer: true}
+ - {address: '[2607:f8b0:400a:801::1003]:1234', is_balancer: true}
+ - {address: '[2607:f8b0:400a:801::1004]:1234', is_balancer: true}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv6-multi-target
+ records:
+ _grpclb._tcp.srv-ipv6-multi-target:
+ - {TTL: '2100', data: 0 0 1234 ipv6-multi-target, type: SRV}
+ ipv6-multi-target:
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1002', type: AAAA}
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1003', type: AAAA}
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1004', type: AAAA}
+- expected_addrs:
+ - {address: '1.2.3.4:1234', is_balancer: true}
+ expected_chosen_service_config: '{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]}]}'
+ expected_lb_policy: round_robin
+ record_to_resolve: srv-ipv4-simple-service-config
+ records:
+ _grpclb._tcp.srv-ipv4-simple-service-config:
+ - {TTL: '2100', data: 0 0 1234 ipv4-simple-service-config, type: SRV}
+ ipv4-simple-service-config:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ srv-ipv4-simple-service-config:
+ - {TTL: '2100', data: 'grpc_config=[{"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: '{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"NoSrvSimpleService","waitForReady":true}]}]}'
+ expected_lb_policy: round_robin
+ record_to_resolve: ipv4-no-srv-simple-service-config
+ records:
+ ipv4-no-srv-simple-service-config:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"NoSrvSimpleService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: ipv4-no-config-for-cpp
+ records:
+ ipv4-no-config-for-cpp:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"clientLanguage":["python"],"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"PythonService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: ipv4-cpp-config-has-zero-percentage
+ records:
+ ipv4-cpp-config-has-zero-percentage:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"percentage":0,"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"CppService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: '{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"CppService","waitForReady":true}]}]}'
+ expected_lb_policy: round_robin
+ record_to_resolve: ipv4-second-language-is-cpp
+ records:
+ ipv4-second-language-is-cpp:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"clientLanguage":["go"],"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"GoService","waitForReady":true}]}]}},{"clientLanguage":["c++"],"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"CppService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: '{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"AlwaysPickedService","waitForReady":true}]}]}'
+ expected_lb_policy: round_robin
+ record_to_resolve: ipv4-config-with-percentages
+ records:
+ ipv4-config-with-percentages:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"percentage":0,"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"NeverPickedService","waitForReady":true}]}]}},{"percentage":100,"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"AlwaysPickedService","waitForReady":true}]}]}}]',
+ type: TXT}
+- expected_addrs:
+ - {address: '1.2.3.4:1234', is_balancer: true}
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv4-target-has-backend-and-balancer
+ records:
+ _grpclb._tcp.srv-ipv4-target-has-backend-and-balancer:
+ - {TTL: '2100', data: 0 0 1234 balancer-for-ipv4-has-backend-and-balancer, type: SRV}
+ balancer-for-ipv4-has-backend-and-balancer:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ srv-ipv4-target-has-backend-and-balancer:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+- expected_addrs:
+ - {address: '[2607:f8b0:400a:801::1002]:1234', is_balancer: true}
+ - {address: '[2607:f8b0:400a:801::1002]:443', is_balancer: false}
+ expected_chosen_service_config: null
+ expected_lb_policy: null
+ record_to_resolve: srv-ipv6-target-has-backend-and-balancer
+ records:
+ _grpclb._tcp.srv-ipv6-target-has-backend-and-balancer:
+ - {TTL: '2100', data: 0 0 1234 balancer-for-ipv6-has-backend-and-balancer, type: SRV}
+ balancer-for-ipv6-has-backend-and-balancer:
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1002', type: AAAA}
+ srv-ipv6-target-has-backend-and-balancer:
+ - {TTL: '2100', data: '2607:f8b0:400a:801::1002', type: AAAA}
+- expected_addrs:
+ - {address: '1.2.3.4:443', is_balancer: false}
+ expected_chosen_service_config: '{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooThree","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFour","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFive","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSix","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSeven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEight","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooNine","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTen","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEleven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]}]}'
+ expected_lb_policy: null
+ record_to_resolve: ipv4-config-causing-fallback-to-tcp
+ records:
+ ipv4-config-causing-fallback-to-tcp:
+ - {TTL: '2100', data: 1.2.3.4, type: A}
+ - {TTL: '2100', data: 'grpc_config=[{"serviceConfig":{"loadBalancingPolicy":"round_robin","methodConfig":[{"name":[{"method":"Foo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwo","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooThree","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFour","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooFive","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSix","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooSeven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEight","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooNine","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTen","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooEleven","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]},{"name":[{"method":"FooTwelve","service":"SimpleService","waitForReady":true}]}]}}]',
+ type: TXT}
diff --git a/test/cpp/naming/test_dns_server.py b/test/cpp/naming/test_dns_server.py
new file mode 100755
index 0000000000..9d4b89cffb
--- /dev/null
+++ b/test/cpp/naming/test_dns_server.py
@@ -0,0 +1,134 @@
+#!/usr/bin/env python2.7
+# Copyright 2015 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Starts a local DNS server for use in tests"""
+
+import argparse
+import sys
+import yaml
+import signal
+import os
+
+import twisted
+import twisted.internet
+import twisted.internet.reactor
+import twisted.internet.threads
+import twisted.internet.defer
+import twisted.internet.protocol
+import twisted.names
+import twisted.names.client
+import twisted.names.dns
+import twisted.names.server
+from twisted.names import client, server, common, authority, dns
+import argparse
+
+_SERVER_HEALTH_CHECK_RECORD_NAME = 'health-check-local-dns-server-is-alive.resolver-tests.grpctestingexp' # missing end '.' for twisted syntax
+_SERVER_HEALTH_CHECK_RECORD_DATA = '123.123.123.123'
+
+class NoFileAuthority(authority.FileAuthority):
+ def __init__(self, soa, records):
+ # skip FileAuthority
+ common.ResolverBase.__init__(self)
+ self.soa = soa
+ self.records = records
+
+def start_local_dns_server(args):
+ all_records = {}
+ def _push_record(name, r):
+ print('pushing record: |%s|' % name)
+ if all_records.get(name) is not None:
+ all_records[name].append(r)
+ return
+ all_records[name] = [r]
+
+ def _maybe_split_up_txt_data(name, txt_data, r_ttl):
+ start = 0
+ txt_data_list = []
+ while len(txt_data[start:]) > 0:
+ next_read = len(txt_data[start:])
+ if next_read > 255:
+ next_read = 255
+ txt_data_list.append(txt_data[start:start+next_read])
+ start += next_read
+ _push_record(name, dns.Record_TXT(*txt_data_list, ttl=r_ttl))
+
+ with open(args.records_config_path) as config:
+ test_records_config = yaml.load(config)
+ common_zone_name = test_records_config['resolver_component_tests_common_zone_name']
+ for group in test_records_config['resolver_component_tests']:
+ for name in group['records'].keys():
+ for record in group['records'][name]:
+ r_type = record['type']
+ r_data = record['data']
+ r_ttl = int(record['TTL'])
+ record_full_name = '%s.%s' % (name, common_zone_name)
+ assert record_full_name[-1] == '.'
+ record_full_name = record_full_name[:-1]
+ if r_type == 'A':
+ _push_record(record_full_name, dns.Record_A(r_data, ttl=r_ttl))
+ if r_type == 'AAAA':
+ _push_record(record_full_name, dns.Record_AAAA(r_data, ttl=r_ttl))
+ if r_type == 'SRV':
+ p, w, port, target = r_data.split(' ')
+ p = int(p)
+ w = int(w)
+ port = int(port)
+ target_full_name = '%s.%s' % (target, common_zone_name)
+ r_data = '%s %s %s %s' % (p, w, port, target_full_name)
+ _push_record(record_full_name, dns.Record_SRV(p, w, port, target_full_name, ttl=r_ttl))
+ if r_type == 'TXT':
+ _maybe_split_up_txt_data(record_full_name, r_data, r_ttl)
+ # Server health check record
+ _push_record(_SERVER_HEALTH_CHECK_RECORD_NAME, dns.Record_A(_SERVER_HEALTH_CHECK_RECORD_DATA, ttl=0))
+ soa_record = dns.Record_SOA(mname = common_zone_name)
+ test_domain_com = NoFileAuthority(
+ soa = (common_zone_name, soa_record),
+ records = all_records,
+ )
+ server = twisted.names.server.DNSServerFactory(
+ authorities=[test_domain_com], verbose=2)
+ server.noisy = 2
+ twisted.internet.reactor.listenTCP(args.port, server)
+ dns_proto = twisted.names.dns.DNSDatagramProtocol(server)
+ dns_proto.noisy = 2
+ twisted.internet.reactor.listenUDP(args.port, dns_proto)
+ print('starting local dns server on 127.0.0.1:%s' % args.port)
+ print('starting twisted.internet.reactor')
+ twisted.internet.reactor.suggestThreadPoolSize(1)
+ twisted.internet.reactor.run()
+
+def _quit_on_signal(signum, _frame):
+ print('Received SIGNAL %d. Quitting with exit code 0' % signum)
+ twisted.internet.reactor.stop()
+ sys.stdout.flush()
+ sys.exit(0)
+
+def main():
+ argp = argparse.ArgumentParser(description='Local DNS Server for resolver tests')
+ argp.add_argument('-p', '--port', default=None, type=int,
+ help='Port for DNS server to listen on for TCP and UDP.')
+ argp.add_argument('-r', '--records_config_path', default=None, type=str,
+ help=('Directory of resolver_test_record_groups.yaml file. '
+ 'Defauls to path needed when the test is invoked as part of run_tests.py.'))
+ args = argp.parse_args()
+ signal.signal(signal.SIGALRM, _quit_on_signal)
+ signal.signal(signal.SIGTERM, _quit_on_signal)
+ signal.signal(signal.SIGINT, _quit_on_signal)
+ # Prevent zombies. Tests that use this server are short-lived.
+ signal.alarm(2 * 60)
+ start_local_dns_server(args)
+
+if __name__ == '__main__':
+ main()
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index 912c871482..f5807da81e 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -56,11 +56,7 @@ class ClientRpcContext {
}
virtual void Start(CompletionQueue* cq, const ClientConfig& config) = 0;
- void lock() { mu_.lock(); }
- void unlock() { mu_.unlock(); }
-
- private:
- std::mutex mu_;
+ virtual void TryCancel() = 0;
};
template <class RequestType, class ResponseType>
@@ -73,7 +69,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)>
- start_req,
+ prepare_req,
std::function<void(grpc::Status, ResponseType*, HistogramEntry*)> on_done)
: context_(),
stub_(stub),
@@ -83,7 +79,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
next_state_(State::READY),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req) {}
+ prepare_req_(prepare_req) {}
~ClientRpcContextUnaryImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
StartInternal(cq);
@@ -92,7 +88,8 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
switch (next_state_) {
case State::READY:
start_ = UsageTimer::Now();
- response_reader_ = start_req_(stub_, &context_, req_, cq_);
+ response_reader_ = prepare_req_(stub_, &context_, req_, cq_);
+ response_reader_->StartCall();
next_state_ = State::RESP_DONE;
response_reader_->Finish(&response_, &status_,
ClientRpcContext::tag(this));
@@ -111,10 +108,10 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
}
void StartNewClone(CompletionQueue* cq) override {
auto* clone = new ClientRpcContextUnaryImpl(stub_, req_, next_issue_,
- start_req_, callback_);
- std::lock_guard<ClientRpcContext> lclone(*clone);
+ prepare_req_, callback_);
clone->StartInternal(cq);
}
+ void TryCancel() override { context_.TryCancel(); }
private:
grpc::ClientContext context_;
@@ -130,7 +127,7 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
std::function<std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
CompletionQueue*)>
- start_req_;
+ prepare_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncResponseReader<ResponseType>>
@@ -147,8 +144,6 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
}
};
-typedef std::forward_list<ClientRpcContext*> context_list;
-
template <class StubType, class RequestType>
class AsyncClient : public ClientImpl<StubType, RequestType> {
// Specify which protected members we are using since there is no
@@ -252,29 +247,14 @@ class AsyncClient : public ClientImpl<StubType, RequestType> {
// this thread isn't supposed to shut down
std::lock_guard<std::mutex> l(shutdown_state_[thread_idx]->mutex);
if (shutdown_state_[thread_idx]->shutdown) {
- // We want to delete the context. However, it is possible that
- // another thread that just initiated an action on this
- // context still has its lock even though the action on the
- // context has completed. To delay for that, just grab the
- // lock for serialization. Take a new scope.
- { std::lock_guard<ClientRpcContext> lctx(*ctx); }
+ ctx->TryCancel();
delete ctx;
return true;
}
- bool del = false;
-
- // Create a new scope for a lock_guard'ed region
- {
- std::lock_guard<ClientRpcContext> lctx(*ctx);
- if (!ctx->RunNextState(ok, entry)) {
- // The RPC and callback are done, so clone the ctx
- // and kickstart the new one
- ctx->StartNewClone(cli_cqs_[cq_[thread_idx]].get());
- // set the old version to delete
- del = true;
- }
- }
- if (del) {
+ if (!ctx->RunNextState(ok, entry)) {
+ // The RPC and callback are done, so clone the ctx
+ // and kickstart the new one
+ ctx->StartNewClone(cli_cqs_[cq_[thread_idx]].get());
delete ctx;
}
return true;
@@ -311,15 +291,15 @@ class AsyncUnaryClient final
entry->set_status(s.error_code());
}
static std::unique_ptr<grpc::ClientAsyncResponseReader<SimpleResponse>>
- StartReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
- const SimpleRequest& request, CompletionQueue* cq) {
- return stub->AsyncUnaryCall(ctx, request, cq);
+ PrepareReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
+ const SimpleRequest& request, CompletionQueue* cq) {
+ return stub->PrepareAsyncUnaryCall(ctx, request, cq);
};
static ClientRpcContext* SetupCtx(BenchmarkService::Stub* stub,
std::function<gpr_timespec()> next_issue,
const SimpleRequest& req) {
return new ClientRpcContextUnaryImpl<SimpleRequest, SimpleResponse>(
- stub, req, next_issue, AsyncUnaryClient::StartReq,
+ stub, req, next_issue, AsyncUnaryClient::PrepareReq,
AsyncUnaryClient::CheckDone);
}
};
@@ -332,9 +312,8 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue,
std::function<std::unique_ptr<
grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
- BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*,
- void*)>
- start_req,
+ BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*)>
+ prepare_req,
std::function<void(grpc::Status, ResponseType*)> on_done)
: context_(),
stub_(stub),
@@ -344,7 +323,7 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req) {}
+ prepare_req_(prepare_req) {}
~ClientRpcContextStreamingPingPongImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
StartInternal(cq, config.messages_per_stream());
@@ -407,10 +386,10 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
}
void StartNewClone(CompletionQueue* cq) override {
auto* clone = new ClientRpcContextStreamingPingPongImpl(
- stub_, req_, next_issue_, start_req_, callback_);
- std::lock_guard<ClientRpcContext> lclone(*clone);
+ stub_, req_, next_issue_, prepare_req_, callback_);
clone->StartInternal(cq, messages_per_stream_);
}
+ void TryCancel() override { context_.TryCancel(); }
private:
grpc::ClientContext context_;
@@ -432,10 +411,10 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
State next_state_;
std::function<void(grpc::Status, ResponseType*)> callback_;
std::function<gpr_timespec()> next_issue_;
- std::function<std::unique_ptr<
- grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
- BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*, void*)>
- start_req_;
+ std::function<
+ std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>(
+ BenchmarkService::Stub*, grpc::ClientContext*, CompletionQueue*)>
+ prepare_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncReaderWriter<RequestType, ResponseType>>
@@ -449,8 +428,9 @@ class ClientRpcContextStreamingPingPongImpl : public ClientRpcContext {
cq_ = cq;
messages_per_stream_ = messages_per_stream;
messages_issued_ = 0;
+ stream_ = prepare_req_(stub_, &context_, cq);
next_state_ = State::STREAM_IDLE;
- stream_ = start_req_(stub_, &context_, cq, ClientRpcContext::tag(this));
+ stream_->StartCall(ClientRpcContext::tag(this));
}
};
@@ -469,9 +449,9 @@ class AsyncStreamingPingPongClient final
static void CheckDone(grpc::Status s, SimpleResponse* response) {}
static std::unique_ptr<
grpc::ClientAsyncReaderWriter<SimpleRequest, SimpleResponse>>
- StartReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
- CompletionQueue* cq, void* tag) {
- auto stream = stub->AsyncStreamingCall(ctx, cq, tag);
+ PrepareReq(BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
+ CompletionQueue* cq) {
+ auto stream = stub->PrepareAsyncStreamingCall(ctx, cq);
return stream;
};
static ClientRpcContext* SetupCtx(BenchmarkService::Stub* stub,
@@ -479,7 +459,7 @@ class AsyncStreamingPingPongClient final
const SimpleRequest& req) {
return new ClientRpcContextStreamingPingPongImpl<SimpleRequest,
SimpleResponse>(
- stub, req, next_issue, AsyncStreamingPingPongClient::StartReq,
+ stub, req, next_issue, AsyncStreamingPingPongClient::PrepareReq,
AsyncStreamingPingPongClient::CheckDone);
}
};
@@ -492,8 +472,8 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue,
std::function<std::unique_ptr<grpc::ClientAsyncWriter<RequestType>>(
BenchmarkService::Stub*, grpc::ClientContext*, ResponseType*,
- CompletionQueue*, void*)>
- start_req,
+ CompletionQueue*)>
+ prepare_req,
std::function<void(grpc::Status, ResponseType*)> on_done)
: context_(),
stub_(stub),
@@ -503,7 +483,7 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req) {}
+ prepare_req_(prepare_req) {}
~ClientRpcContextStreamingFromClientImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
StartInternal(cq);
@@ -546,10 +526,10 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
}
void StartNewClone(CompletionQueue* cq) override {
auto* clone = new ClientRpcContextStreamingFromClientImpl(
- stub_, req_, next_issue_, start_req_, callback_);
- std::lock_guard<ClientRpcContext> lclone(*clone);
+ stub_, req_, next_issue_, prepare_req_, callback_);
clone->StartInternal(cq);
}
+ void TryCancel() override { context_.TryCancel(); }
private:
grpc::ClientContext context_;
@@ -570,17 +550,17 @@ class ClientRpcContextStreamingFromClientImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue_;
std::function<std::unique_ptr<grpc::ClientAsyncWriter<RequestType>>(
BenchmarkService::Stub*, grpc::ClientContext*, ResponseType*,
- CompletionQueue*, void*)>
- start_req_;
+ CompletionQueue*)>
+ prepare_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncWriter<RequestType>> stream_;
void StartInternal(CompletionQueue* cq) {
cq_ = cq;
- stream_ = start_req_(stub_, &context_, &response_, cq,
- ClientRpcContext::tag(this));
+ stream_ = prepare_req_(stub_, &context_, &response_, cq);
next_state_ = State::STREAM_IDLE;
+ stream_->StartCall(ClientRpcContext::tag(this));
}
};
@@ -597,10 +577,10 @@ class AsyncStreamingFromClientClient final
private:
static void CheckDone(grpc::Status s, SimpleResponse* response) {}
- static std::unique_ptr<grpc::ClientAsyncWriter<SimpleRequest>> StartReq(
+ static std::unique_ptr<grpc::ClientAsyncWriter<SimpleRequest>> PrepareReq(
BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
- SimpleResponse* resp, CompletionQueue* cq, void* tag) {
- auto stream = stub->AsyncStreamingFromClient(ctx, resp, cq, tag);
+ SimpleResponse* resp, CompletionQueue* cq) {
+ auto stream = stub->PrepareAsyncStreamingFromClient(ctx, resp, cq);
return stream;
};
static ClientRpcContext* SetupCtx(BenchmarkService::Stub* stub,
@@ -608,7 +588,7 @@ class AsyncStreamingFromClientClient final
const SimpleRequest& req) {
return new ClientRpcContextStreamingFromClientImpl<SimpleRequest,
SimpleResponse>(
- stub, req, next_issue, AsyncStreamingFromClientClient::StartReq,
+ stub, req, next_issue, AsyncStreamingFromClientClient::PrepareReq,
AsyncStreamingFromClientClient::CheckDone);
}
};
@@ -621,8 +601,8 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue,
std::function<std::unique_ptr<grpc::ClientAsyncReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
- CompletionQueue*, void*)>
- start_req,
+ CompletionQueue*)>
+ prepare_req,
std::function<void(grpc::Status, ResponseType*)> on_done)
: context_(),
stub_(stub),
@@ -632,7 +612,7 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req) {}
+ prepare_req_(prepare_req) {}
~ClientRpcContextStreamingFromServerImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
StartInternal(cq);
@@ -664,10 +644,10 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
}
void StartNewClone(CompletionQueue* cq) override {
auto* clone = new ClientRpcContextStreamingFromServerImpl(
- stub_, req_, next_issue_, start_req_, callback_);
- std::lock_guard<ClientRpcContext> lclone(*clone);
+ stub_, req_, next_issue_, prepare_req_, callback_);
clone->StartInternal(cq);
}
+ void TryCancel() override { context_.TryCancel(); }
private:
grpc::ClientContext context_;
@@ -682,8 +662,8 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue_;
std::function<std::unique_ptr<grpc::ClientAsyncReader<ResponseType>>(
BenchmarkService::Stub*, grpc::ClientContext*, const RequestType&,
- CompletionQueue*, void*)>
- start_req_;
+ CompletionQueue*)>
+ prepare_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::ClientAsyncReader<ResponseType>> stream_;
@@ -691,9 +671,9 @@ class ClientRpcContextStreamingFromServerImpl : public ClientRpcContext {
void StartInternal(CompletionQueue* cq) {
// TODO(vjpai): Add support to rate-pace this
cq_ = cq;
+ stream_ = prepare_req_(stub_, &context_, req_, cq);
next_state_ = State::STREAM_IDLE;
- stream_ =
- start_req_(stub_, &context_, req_, cq, ClientRpcContext::tag(this));
+ stream_->StartCall(ClientRpcContext::tag(this));
}
};
@@ -710,10 +690,10 @@ class AsyncStreamingFromServerClient final
private:
static void CheckDone(grpc::Status s, SimpleResponse* response) {}
- static std::unique_ptr<grpc::ClientAsyncReader<SimpleResponse>> StartReq(
+ static std::unique_ptr<grpc::ClientAsyncReader<SimpleResponse>> PrepareReq(
BenchmarkService::Stub* stub, grpc::ClientContext* ctx,
- const SimpleRequest& req, CompletionQueue* cq, void* tag) {
- auto stream = stub->AsyncStreamingFromServer(ctx, req, cq, tag);
+ const SimpleRequest& req, CompletionQueue* cq) {
+ auto stream = stub->PrepareAsyncStreamingFromServer(ctx, req, cq);
return stream;
};
static ClientRpcContext* SetupCtx(BenchmarkService::Stub* stub,
@@ -721,7 +701,7 @@ class AsyncStreamingFromServerClient final
const SimpleRequest& req) {
return new ClientRpcContextStreamingFromServerImpl<SimpleRequest,
SimpleResponse>(
- stub, req, next_issue, AsyncStreamingFromServerClient::StartReq,
+ stub, req, next_issue, AsyncStreamingFromServerClient::PrepareReq,
AsyncStreamingFromServerClient::CheckDone);
}
};
@@ -733,8 +713,8 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue,
std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
grpc::GenericStub*, grpc::ClientContext*,
- const grpc::string& method_name, CompletionQueue*, void*)>
- start_req,
+ const grpc::string& method_name, CompletionQueue*)>
+ prepare_req,
std::function<void(grpc::Status, ByteBuffer*)> on_done)
: context_(),
stub_(stub),
@@ -744,7 +724,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req) {}
+ prepare_req_(prepare_req) {}
~ClientRpcContextGenericStreamingImpl() override {}
void Start(CompletionQueue* cq, const ClientConfig& config) override {
StartInternal(cq, config.messages_per_stream());
@@ -807,10 +787,10 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
}
void StartNewClone(CompletionQueue* cq) override {
auto* clone = new ClientRpcContextGenericStreamingImpl(
- stub_, req_, next_issue_, start_req_, callback_);
- std::lock_guard<ClientRpcContext> lclone(*clone);
+ stub_, req_, next_issue_, prepare_req_, callback_);
clone->StartInternal(cq, messages_per_stream_);
}
+ void TryCancel() override { context_.TryCancel(); }
private:
grpc::ClientContext context_;
@@ -834,8 +814,8 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
std::function<gpr_timespec()> next_issue_;
std::function<std::unique_ptr<grpc::GenericClientAsyncReaderWriter>(
grpc::GenericStub*, grpc::ClientContext*, const grpc::string&,
- CompletionQueue*, void*)>
- start_req_;
+ CompletionQueue*)>
+ prepare_req_;
grpc::Status status_;
double start_;
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> stream_;
@@ -850,9 +830,9 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
"/grpc.testing.BenchmarkService/StreamingCall");
messages_per_stream_ = messages_per_stream;
messages_issued_ = 0;
+ stream_ = prepare_req_(stub_, &context_, kMethodName, cq);
next_state_ = State::STREAM_IDLE;
- stream_ = start_req_(stub_, &context_, kMethodName, cq,
- ClientRpcContext::tag(this));
+ stream_->StartCall(ClientRpcContext::tag(this));
}
};
@@ -874,17 +854,17 @@ class GenericAsyncStreamingClient final
private:
static void CheckDone(grpc::Status s, ByteBuffer* response) {}
- static std::unique_ptr<grpc::GenericClientAsyncReaderWriter> StartReq(
+ static std::unique_ptr<grpc::GenericClientAsyncReaderWriter> PrepareReq(
grpc::GenericStub* stub, grpc::ClientContext* ctx,
- const grpc::string& method_name, CompletionQueue* cq, void* tag) {
- auto stream = stub->Call(ctx, method_name, cq, tag);
+ const grpc::string& method_name, CompletionQueue* cq) {
+ auto stream = stub->PrepareCall(ctx, method_name, cq);
return stream;
};
static ClientRpcContext* SetupCtx(grpc::GenericStub* stub,
std::function<gpr_timespec()> next_issue,
const ByteBuffer& req) {
return new ClientRpcContextGenericStreamingImpl(
- stub, req, next_issue, GenericAsyncStreamingClient::StartReq,
+ stub, req, next_issue, GenericAsyncStreamingClient::PrepareReq,
GenericAsyncStreamingClient::CheckDone);
}
};
diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc
index 3c99bda144..42ebeff41d 100644
--- a/test/cpp/qps/report.cc
+++ b/test/cpp/qps/report.cc
@@ -107,8 +107,8 @@ void GprLogReporter::ReportCoreStats(const char* name, int idx,
grpc_stats_counter_name[i], data.counters[i]);
}
for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) {
- gpr_log(GPR_DEBUG, "%s[%d].%s = %lf/%lf/%lf (50/95/99%%-ile)", name, idx,
- grpc_stats_histogram_name[i],
+ gpr_log(GPR_DEBUG, "%s[%d].%s = %.1lf/%.1lf/%.1lf (50/95/99%%-ile)", name,
+ idx, grpc_stats_histogram_name[i],
grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 50),
grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 95),
grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 99));
diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc
index cac01a7307..8fb51bc663 100644
--- a/test/cpp/util/byte_buffer_test.cc
+++ b/test/cpp/util/byte_buffer_test.cc
@@ -93,7 +93,7 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) {
std::vector<Slice> slices;
slices.push_back(Slice(hello, Slice::STEAL_REF));
slices.push_back(Slice(world, Slice::STEAL_REF));
- grpc_byte_buffer* send_buffer = nullptr;
+ ByteBuffer send_buffer;
bool owned = false;
ByteBuffer buffer(&slices[0], 2);
slices.clear();
@@ -101,8 +101,7 @@ TEST_F(ByteBufferTest, SerializationMakesCopy) {
buffer, &send_buffer, &owned);
EXPECT_TRUE(status.ok());
EXPECT_TRUE(owned);
- EXPECT_TRUE(send_buffer != nullptr);
- grpc_byte_buffer_destroy(send_buffer);
+ EXPECT_TRUE(send_buffer.Valid());
}
} // namespace
diff --git a/test/distrib/cpp/run_distrib_test_cmake.sh b/test/distrib/cpp/run_distrib_test_cmake.sh
new file mode 100755
index 0000000000..ead8cc10bc
--- /dev/null
+++ b/test/distrib/cpp/run_distrib_test_cmake.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+# Copyright 2017 gRPC authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -ex
+
+cd $(dirname $0)/../../..
+
+echo "deb http://ftp.debian.org/debian jessie-backports main" | tee /etc/apt/sources.list.d/jessie-backports.list
+apt-get update
+#apt-get install -t jessie-backports -y libc-ares-dev # we need specifically version 1.12
+apt-get install -t jessie-backports -y libssl-dev
+
+# Install c-ares
+cd third_party/cares/cares
+git fetch origin
+git checkout cares-1_13_0
+mkdir -p cmake/build
+cd cmake/build
+cmake -DCMAKE_BUILD_TYPE=Release ../..
+make -j4 install
+cd ../../../../..
+rm -rf third_party/cares/cares # wipe out to prevent influencing the grpc build
+
+# Install zlib
+cd third_party/zlib
+mkdir -p cmake/build
+cd cmake/build
+cmake -DCMAKE_BUILD_TYPE=Release ../..
+make -j4 install
+cd ../../../..
+rm -rf third_party/zlib # wipe out to prevent influencing the grpc build
+
+# Install protobuf
+cd third_party/protobuf
+mkdir -p cmake/build
+cd cmake/build
+cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ..
+make -j4 install
+cd ../../../..
+rm -rf third_party/protobuf # wipe out to prevent influencing the grpc build
+
+# Install gRPC
+mkdir -p cmake/build
+cd cmake/build
+cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_CARES_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DCMAKE_BUILD_TYPE=Release ../..
+make -j4 install
+cd ../..
+
+# Build helloworld example using cmake
+cd examples/cpp/helloworld
+mkdir -p cmake/build
+cd cmake/build
+cmake ../..
+make
+
diff --git a/test/distrib/cpp/run_distrib_test.sh b/test/distrib/cpp/run_distrib_test_routeguide.sh
index b043075d93..b043075d93 100755
--- a/test/distrib/cpp/run_distrib_test.sh
+++ b/test/distrib/cpp/run_distrib_test_routeguide.sh