diff options
Diffstat (limited to 'test')
24 files changed, 955 insertions, 155 deletions
diff --git a/test/build/OWNERS b/test/build/OWNERS deleted file mode 100644 index 8dca75ce91..0000000000 --- a/test/build/OWNERS +++ /dev/null @@ -1,4 +0,0 @@ -@ctiller -@markdroth -@dgquintas - diff --git a/test/core/OWNERS b/test/core/OWNERS deleted file mode 100644 index 986c9a1c3c..0000000000 --- a/test/core/OWNERS +++ /dev/null @@ -1,5 +0,0 @@ -set noparent -@ctiller -@markdroth -@dgquintas - diff --git a/test/core/compression/stream_compression_test.c b/test/core/compression/stream_compression_test.c new file mode 100644 index 0000000000..e576507aaf --- /dev/null +++ b/test/core/compression/stream_compression_test.c @@ -0,0 +1,292 @@ +/* + * + * 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 <string.h> + +#include <grpc/grpc.h> +#include <grpc/slice_buffer.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> + +#include "src/core/lib/compression/stream_compression.h" + +static void generate_random_payload(char *payload, size_t size) { + size_t i; + static const char chars[] = "abcdefghijklmnopqrstuvwxyz1234567890"; + for (i = 0; i < size - 1; ++i) { + payload[i] = chars[rand() % (int)(sizeof(chars) - 1)]; + } + payload[size - 1] = '\0'; +} + +static bool slice_buffer_equals_string(grpc_slice_buffer *buf, + const char *str) { + size_t i; + if (buf->length != strlen(str)) { + return false; + } + size_t pointer = 0; + for (i = 0; i < buf->count; i++) { + size_t slice_len = GRPC_SLICE_LENGTH(buf->slices[i]); + if (0 != strncmp(str + pointer, + (char *)GRPC_SLICE_START_PTR(buf->slices[i]), slice_len)) { + return false; + } + pointer += slice_len; + } + return true; +} + +static void test_stream_compression_simple_compress_decompress() { + const char test_str[] = "aaaaaaabbbbbbbccccccctesttesttest"; + grpc_slice_buffer source, relay, sink; + grpc_slice_buffer_init(&source); + 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 *decompress_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + bool end_of_context; + size_t output_size; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(output_size == sizeof(test_str) - 1); + grpc_stream_compression_context_destroy(compress_ctx); + grpc_stream_compression_context_destroy(decompress_ctx); + + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); + + grpc_slice_buffer_destroy(&source); + grpc_slice_buffer_destroy(&relay); + grpc_slice_buffer_destroy(&sink); +} + +static void +test_stream_compression_simple_compress_decompress_with_output_size_constraint() { + const char test_str[] = "aaaaaaabbbbbbbccccccctesttesttest"; + grpc_slice_buffer source, relay, sink; + grpc_slice_buffer_init(&source); + 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 *decompress_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + grpc_stream_compression_context_destroy(compress_ctx); + + bool end_of_context; + size_t output_size; + size_t max_output_size = 2; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + max_output_size, &end_of_context)); + GPR_ASSERT(output_size == max_output_size); + GPR_ASSERT(end_of_context == false); + grpc_slice slice_recv = grpc_slice_buffer_take_first(&sink); + char *str_recv = (char *)GRPC_SLICE_START_PTR(slice_recv); + GPR_ASSERT(GRPC_SLICE_LENGTH(slice_recv) == max_output_size); + GPR_ASSERT(0 == strncmp(test_str, str_recv, max_output_size)); + grpc_slice_unref(slice_recv); + + size_t remaining_size = sizeof(test_str) - 1 - max_output_size; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + remaining_size, &end_of_context)); + GPR_ASSERT(output_size == remaining_size); + GPR_ASSERT(end_of_context == true); + + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str + max_output_size)); + + grpc_stream_compression_context_destroy(decompress_ctx); + grpc_slice_buffer_destroy(&source); + grpc_slice_buffer_destroy(&relay); + grpc_slice_buffer_destroy(&sink); +} + +#define LARGE_DATA_SIZE (1024 * 1024) +static void +test_stream_compression_simple_compress_decompress_with_large_data() { + char *test_str = gpr_malloc(LARGE_DATA_SIZE * sizeof(char)); + generate_random_payload(test_str, LARGE_DATA_SIZE); + grpc_slice_buffer source, relay, sink; + grpc_slice_buffer_init(&source); + 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 *decompress_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + bool end_of_context; + size_t output_size; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(output_size == LARGE_DATA_SIZE - 1); + grpc_stream_compression_context_destroy(compress_ctx); + grpc_stream_compression_context_destroy(decompress_ctx); + + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); + + grpc_slice_buffer_destroy(&source); + grpc_slice_buffer_destroy(&relay); + grpc_slice_buffer_destroy(&sink); + gpr_free(test_str); +} + +static void test_stream_compression_drop_context() { + const char test_str[] = "aaaaaaabbbbbbbccccccc"; + const char test_str2[] = "dddddddeeeeeeefffffffggggg"; + grpc_slice_buffer source, relay, sink; + grpc_slice_buffer_init(&source); + 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_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + grpc_stream_compression_context_destroy(compress_ctx); + + compress_ctx = + grpc_stream_compression_context_create(GRPC_STREAM_COMPRESSION_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + grpc_stream_compression_context_destroy(compress_ctx); + + /* Concatenate the two compressed sliced into one to test decompressing two + * contexts */ + grpc_slice slice1 = grpc_slice_buffer_take_first(&relay); + grpc_slice slice2 = grpc_slice_buffer_take_first(&relay); + grpc_slice slice3 = + grpc_slice_malloc(GRPC_SLICE_LENGTH(slice1) + GRPC_SLICE_LENGTH(slice2)); + memcpy(GRPC_SLICE_START_PTR(slice3), GRPC_SLICE_START_PTR(slice1), + GRPC_SLICE_LENGTH(slice1)); + memcpy(GRPC_SLICE_START_PTR(slice3) + GRPC_SLICE_LENGTH(slice1), + GRPC_SLICE_START_PTR(slice2), GRPC_SLICE_LENGTH(slice2)); + grpc_slice_unref(slice1); + grpc_slice_unref(slice2); + grpc_slice_buffer_add(&relay, slice3); + + grpc_stream_compression_context *decompress_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_DECOMPRESS); + bool end_of_context; + size_t output_size; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(end_of_context == true); + GPR_ASSERT(output_size == sizeof(test_str) - 1); + + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); + grpc_stream_compression_context_destroy(decompress_ctx); + grpc_slice_buffer_destroy(&sink); + + grpc_slice_buffer_init(&sink); + decompress_ctx = grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_DECOMPRESS); + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(end_of_context == true); + GPR_ASSERT(output_size == sizeof(test_str2) - 1); + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str2)); + grpc_stream_compression_context_destroy(decompress_ctx); + + grpc_slice_buffer_destroy(&source); + grpc_slice_buffer_destroy(&relay); + grpc_slice_buffer_destroy(&sink); +} + +static void test_stream_compression_sync_flush() { + const char test_str[] = "aaaaaaabbbbbbbccccccc"; + const char test_str2[] = "dddddddeeeeeeefffffffggggg"; + grpc_slice_buffer source, relay, sink; + grpc_slice_buffer_init(&source); + 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_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, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_SYNC)); + + grpc_stream_compression_context *decompress_ctx = + grpc_stream_compression_context_create( + GRPC_STREAM_COMPRESSION_DECOMPRESS); + bool end_of_context; + size_t output_size; + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(end_of_context == false); + GPR_ASSERT(output_size == sizeof(test_str) - 1); + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str)); + grpc_slice_buffer_destroy(&sink); + + grpc_slice_buffer_init(&sink); + slice = grpc_slice_from_static_string(test_str2); + grpc_slice_buffer_add(&source, slice); + GPR_ASSERT(grpc_stream_compress(compress_ctx, &source, &relay, NULL, + ~(size_t)0, + GRPC_STREAM_COMPRESSION_FLUSH_FINISH)); + grpc_stream_compression_context_destroy(compress_ctx); + + GPR_ASSERT(grpc_stream_decompress(decompress_ctx, &relay, &sink, &output_size, + ~(size_t)0, &end_of_context)); + GPR_ASSERT(end_of_context == true); + GPR_ASSERT(output_size == sizeof(test_str2) - 1); + GPR_ASSERT(slice_buffer_equals_string(&sink, test_str2)); + grpc_stream_compression_context_destroy(decompress_ctx); + + grpc_slice_buffer_destroy(&source); + grpc_slice_buffer_destroy(&relay); + grpc_slice_buffer_destroy(&sink); +} + +int main(int argc, char **argv) { + grpc_init(); + test_stream_compression_simple_compress_decompress(); + test_stream_compression_simple_compress_decompress_with_output_size_constraint(); + test_stream_compression_simple_compress_decompress_with_large_data(); + test_stream_compression_sync_flush(); + test_stream_compression_drop_context(); + grpc_shutdown(); + + return 0; +} diff --git a/test/core/end2end/fixtures/inproc.c b/test/core/end2end/fixtures/inproc.c new file mode 100644 index 0000000000..6f742f0293 --- /dev/null +++ b/test/core/end2end/fixtures/inproc.c @@ -0,0 +1,96 @@ +/* + * + * 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 "test/core/end2end/end2end_tests.h" + +#include <string.h> + +#include <grpc/support/alloc.h> +#include <grpc/support/host_port.h> +#include <grpc/support/log.h> +#include <grpc/support/sync.h> +#include <grpc/support/thd.h> +#include <grpc/support/useful.h> +#include "src/core/ext/filters/client_channel/client_channel.h" +#include "src/core/ext/filters/http/server/http_server_filter.h" +#include "src/core/ext/transport/inproc/inproc_transport.h" +#include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/surface/channel.h" +#include "src/core/lib/surface/server.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" + +typedef struct inproc_fixture_data { + bool dummy; // reserved for future expansion. Struct can't be empty +} inproc_fixture_data; + +static grpc_end2end_test_fixture inproc_create_fixture( + grpc_channel_args *client_args, grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + inproc_fixture_data *ffd = gpr_malloc(sizeof(inproc_fixture_data)); + memset(&f, 0, sizeof(f)); + + f.fixture_data = ffd; + f.cq = grpc_completion_queue_create_for_next(NULL); + f.shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + + return f; +} + +void inproc_init_client(grpc_end2end_test_fixture *f, + grpc_channel_args *client_args) { + f->client = grpc_inproc_channel_create(f->server, client_args, NULL); + GPR_ASSERT(f->client); +} + +void inproc_init_server(grpc_end2end_test_fixture *f, + grpc_channel_args *server_args) { + if (f->server) { + grpc_server_destroy(f->server); + } + f->server = grpc_server_create(server_args, NULL); + grpc_server_register_completion_queue(f->server, f->cq, NULL); + grpc_server_start(f->server); +} + +void inproc_tear_down(grpc_end2end_test_fixture *f) { + inproc_fixture_data *ffd = f->fixture_data; + gpr_free(ffd); +} + +/* All test configurations */ +static grpc_end2end_test_config configs[] = { + {"inproc", FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER, inproc_create_fixture, + inproc_init_client, inproc_init_server, inproc_tear_down}, +}; + +int main(int argc, char **argv) { + size_t i; + + grpc_test_init(argc, argv); + grpc_end2end_tests_pre_init(); + grpc_init(); + + for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) { + grpc_end2end_tests(argc, argv, configs[i]); + } + + grpc_shutdown(); + + return 0; +} diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 6dffacf9d7..6878964c4f 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -24,15 +24,15 @@ import hashlib FixtureOptions = collections.namedtuple( 'FixtureOptions', - 'fullstack includes_proxy dns_resolver secure platforms ci_mac tracing exclude_configs exclude_iomgrs large_writes enables_compression') + 'fullstack includes_proxy dns_resolver name_resolution secure platforms ci_mac tracing exclude_configs exclude_iomgrs large_writes enables_compression supports_compression is_inproc is_http2') default_unsecure_fixture_options = FixtureOptions( - True, False, True, False, ['windows', 'linux', 'mac', 'posix'], True, False, [], [], True, False) + True, False, True, True, False, ['windows', 'linux', 'mac', 'posix'], True, False, [], [], True, False, True, False, True) socketpair_unsecure_fixture_options = default_unsecure_fixture_options._replace(fullstack=False, dns_resolver=False) default_secure_fixture_options = default_unsecure_fixture_options._replace(secure=True) uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['linux', 'mac', 'posix'], exclude_iomgrs=['uv']) fd_unsecure_fixture_options = default_unsecure_fixture_options._replace( dns_resolver=False, fullstack=False, platforms=['linux', 'mac', 'posix'], exclude_iomgrs=['uv']) - +inproc_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, fullstack=False, name_resolution=False, supports_compression=False, is_inproc=True, is_http2=False) # maps fixture name to whether it requires the security library END2END_FIXTURES = { @@ -64,12 +64,13 @@ END2END_FIXTURES = { 'h2_ssl_proxy': default_secure_fixture_options._replace( includes_proxy=True, ci_mac=False, exclude_iomgrs=['uv']), 'h2_uds': uds_fixture_options, + 'inproc': inproc_fixture_options } TestOptions = collections.namedtuple( 'TestOptions', - 'needs_fullstack needs_dns proxyable secure traceable cpu_cost exclude_iomgrs large_writes flaky allow_compression') -default_test_options = TestOptions(False, False, True, False, True, 1.0, [], False, False, True) + 'needs_fullstack needs_dns needs_names proxyable secure traceable cpu_cost exclude_iomgrs large_writes flaky allows_compression needs_compression exclude_inproc needs_http2') +default_test_options = TestOptions(False, False, False, True, False, True, 1.0, [], False, False, True, False, False, False) connectivity_test_options = default_test_options._replace(needs_fullstack=True) LOWCPU = 0.1 @@ -77,12 +78,12 @@ LOWCPU = 0.1 # maps test names to options END2END_TESTS = { 'authority_not_supported': default_test_options, - 'bad_hostname': default_test_options, + 'bad_hostname': default_test_options._replace(needs_names=True), 'bad_ping': connectivity_test_options._replace(proxyable=False), 'binary_metadata': default_test_options._replace(cpu_cost=LOWCPU), 'resource_quota_server': default_test_options._replace(large_writes=True, proxyable=False, - allow_compression=False), + allows_compression=False), 'call_creds': default_test_options._replace(secure=True), 'cancel_after_accept': default_test_options._replace(cpu_cost=LOWCPU), 'cancel_after_client_done': default_test_options._replace(cpu_cost=LOWCPU), @@ -91,17 +92,17 @@ END2END_TESTS = { 'cancel_before_invoke': default_test_options._replace(cpu_cost=LOWCPU), 'cancel_in_a_vacuum': default_test_options._replace(cpu_cost=LOWCPU), 'cancel_with_status': default_test_options._replace(cpu_cost=LOWCPU), - 'compressed_payload': default_test_options._replace(proxyable=False), - 'connectivity': connectivity_test_options._replace( + 'compressed_payload': default_test_options._replace(proxyable=False,needs_compression=True), + 'connectivity': connectivity_test_options._replace(needs_names=True, proxyable=False, cpu_cost=LOWCPU, exclude_iomgrs=['uv']), 'default_host': default_test_options._replace(needs_fullstack=True, - needs_dns=True), - 'disappearing_server': connectivity_test_options._replace(flaky=True), + needs_dns=True,needs_names=True), + 'disappearing_server': connectivity_test_options._replace(flaky=True,needs_names=True), 'empty_batch': default_test_options._replace(cpu_cost=LOWCPU), 'filter_causes_close': default_test_options._replace(cpu_cost=LOWCPU), 'filter_call_init_fails': default_test_options, 'filter_latency': default_test_options._replace(cpu_cost=LOWCPU), - 'graceful_server_shutdown': default_test_options._replace(cpu_cost=LOWCPU), + 'graceful_server_shutdown': default_test_options._replace(cpu_cost=LOWCPU,exclude_inproc=True), 'hpack_size': default_test_options._replace(proxyable=False, traceable=False, cpu_cost=LOWCPU), @@ -109,11 +110,13 @@ END2END_TESTS = { 'idempotent_request': default_test_options, 'invoke_large_request': default_test_options, 'keepalive_timeout': default_test_options._replace(proxyable=False, - cpu_cost=LOWCPU), + cpu_cost=LOWCPU, + needs_http2=True), 'large_metadata': default_test_options, 'max_concurrent_streams': default_test_options._replace( - proxyable=False, cpu_cost=LOWCPU), - 'max_connection_age': default_test_options._replace(cpu_cost=LOWCPU), + proxyable=False, cpu_cost=LOWCPU, exclude_inproc=True), + 'max_connection_age': default_test_options._replace(cpu_cost=LOWCPU, + exclude_inproc=True), 'max_connection_idle': connectivity_test_options._replace( proxyable=False, exclude_iomgrs=['uv'], cpu_cost=LOWCPU), 'max_message_length': default_test_options._replace(cpu_cost=LOWCPU), @@ -151,6 +154,9 @@ def compatible(f, t): if END2END_TESTS[t].needs_dns: if not END2END_FIXTURES[f].dns_resolver: return False + if END2END_TESTS[t].needs_names: + if not END2END_FIXTURES[f].name_resolution: + return False if not END2END_TESTS[t].proxyable: if END2END_FIXTURES[f].includes_proxy: return False @@ -160,9 +166,18 @@ def compatible(f, t): if END2END_TESTS[t].large_writes: if not END2END_FIXTURES[f].large_writes: return False - if not END2END_TESTS[t].allow_compression: + if not END2END_TESTS[t].allows_compression: if END2END_FIXTURES[f].enables_compression: return False + if END2END_TESTS[t].needs_compression: + if not END2END_FIXTURES[f].supports_compression: + return False + if END2END_TESTS[t].exclude_inproc: + if END2END_FIXTURES[f].is_inproc: + return False + if END2END_TESTS[t].needs_http2: + if not END2END_FIXTURES[f].is_http2: + return False return True diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index 3312f4e596..ea9ad03513 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -19,14 +19,18 @@ load("//bazel:grpc_build_system.bzl", "grpc_sh_test", "grpc_cc_binary", "grpc_cc def fixture_options(fullstack=True, includes_proxy=False, dns_resolver=True, - secure=True, tracing=False, - platforms=['windows', 'linux', 'mac', 'posix']): + name_resolution=True, secure=True, tracing=False, + platforms=['windows', 'linux', 'mac', 'posix'], + is_inproc=False, is_http2=True): return struct( fullstack=fullstack, includes_proxy=includes_proxy, dns_resolver=dns_resolver, + name_resolution=name_resolution, secure=secure, tracing=tracing, + is_inproc=is_inproc, + is_http2=is_http2 #platforms=platforms ) @@ -55,24 +59,31 @@ END2END_FIXTURES = { 'h2_ssl_proxy': fixture_options(includes_proxy=True, secure=True), 'h2_uds': fixture_options(dns_resolver=False, platforms=['linux', 'mac', 'posix']), + 'inproc': fixture_options(fullstack=False, dns_resolver=False, + name_resolution=False, is_inproc=True, + is_http2=False), } -def test_options(needs_fullstack=False, needs_dns=False, proxyable=True, - secure=False, traceable=False): +def test_options(needs_fullstack=False, needs_dns=False, needs_names=False, + proxyable=True, secure=False, traceable=False, + exclude_inproc=False, needs_http2=False): return struct( needs_fullstack=needs_fullstack, needs_dns=needs_dns, + needs_names=needs_names, proxyable=proxyable, secure=secure, - traceable=traceable + traceable=traceable, + exclude_inproc=exclude_inproc, + needs_http2=needs_http2 ) # maps test names to options END2END_TESTS = { - 'bad_hostname': test_options(), - 'bad_ping': test_options(), + 'bad_hostname': test_options(needs_names=True), + 'bad_ping': test_options(needs_fullstack=True,proxyable=False), 'binary_metadata': test_options(), 'resource_quota_server': test_options(proxyable=False), 'call_creds': test_options(secure=True), @@ -83,22 +94,25 @@ END2END_TESTS = { 'cancel_before_invoke': test_options(), 'cancel_in_a_vacuum': test_options(), 'cancel_with_status': test_options(), - 'compressed_payload': test_options(proxyable=False), - 'connectivity': test_options(needs_fullstack=True, proxyable=False), - 'default_host': test_options(needs_fullstack=True, needs_dns=True), - 'disappearing_server': test_options(needs_fullstack=True), + 'compressed_payload': test_options(proxyable=False, exclude_inproc=True), + 'connectivity': test_options(needs_fullstack=True, needs_names=True, + proxyable=False), + 'default_host': test_options(needs_fullstack=True, needs_dns=True, + needs_names=True), + 'disappearing_server': test_options(needs_fullstack=True,needs_names=True), 'empty_batch': test_options(), 'filter_causes_close': test_options(), 'filter_call_init_fails': test_options(), - 'graceful_server_shutdown': test_options(), - 'hpack_size': test_options(proxyable=False, traceable=False), + 'graceful_server_shutdown': test_options(exclude_inproc=True), + 'hpack_size': test_options(proxyable=False, traceable=False, + exclude_inproc=True), 'high_initial_seqno': test_options(), 'idempotent_request': test_options(), 'invoke_large_request': test_options(), - 'keepalive_timeout': test_options(proxyable=False), + 'keepalive_timeout': test_options(proxyable=False, needs_http2=True), 'large_metadata': test_options(), - 'max_concurrent_streams': test_options(proxyable=False), - 'max_connection_age': test_options(), + 'max_concurrent_streams': test_options(proxyable=False, exclude_inproc=True), + 'max_connection_age': test_options(exclude_inproc=True), 'max_connection_idle': test_options(needs_fullstack=True, proxyable=False), 'max_message_length': test_options(), 'negative_deadline': test_options(), @@ -136,12 +150,21 @@ def compatible(fopt, topt): if topt.needs_dns: if not fopt.dns_resolver: return False + if topt.needs_names: + if not fopt.name_resolution: + return False if not topt.proxyable: if fopt.includes_proxy: return False if not topt.traceable: if fopt.tracing: return False + if topt.exclude_inproc: + if fopt.is_inproc: + return False + if topt.needs_http2: + if not fopt.is_http2: + return False return True diff --git a/test/cpp/OWNERS b/test/cpp/OWNERS deleted file mode 100644 index 986c9a1c3c..0000000000 --- a/test/cpp/OWNERS +++ /dev/null @@ -1,5 +0,0 @@ -set noparent -@ctiller -@markdroth -@dgquintas - diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 7b78071217..7cb7b262de 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -212,14 +212,16 @@ class ServerBuilderSyncPluginDisabler : public ::grpc::ServerBuilderOption { class TestScenario { public: - TestScenario(bool non_block, const grpc::string& creds_type, bool hcs, - const grpc::string& content) + TestScenario(bool non_block, bool inproc_stub, const grpc::string& creds_type, + bool hcs, const grpc::string& content) : disable_blocking(non_block), + inproc(inproc_stub), health_check_service(hcs), credentials_type(creds_type), message_content(content) {} void Log() const; bool disable_blocking; + bool inproc; bool health_check_service; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -232,6 +234,7 @@ static std::ostream& operator<<(std::ostream& out, const TestScenario& scenario) { return out << "TestScenario{disable_blocking=" << (scenario.disable_blocking ? "true" : "false") + << ", inproc=" << (scenario.inproc ? "true" : "false") << ", credentials='" << scenario.credentials_type << ", health_check_service=" << (scenario.health_check_service ? "true" : "false") @@ -294,7 +297,9 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> { auto channel_creds = GetCredentialsProvider()->GetChannelCredentials( GetParam().credentials_type, &args); std::shared_ptr<Channel> channel = - CreateCustomChannel(server_address_.str(), channel_creds, args); + !(GetParam().inproc) + ? CreateCustomChannel(server_address_.str(), channel_creds, args) + : server_->InProcessChannel(args); stub_ = grpc::testing::EchoTestService::NewStub(channel); } @@ -512,7 +517,7 @@ TEST_P(AsyncEnd2endTest, SimpleClientStreamingWithCoalescingApi) { // up until server read is initiated. For write of send_request smaller than // the flow control window size, the request can take the free ride with // initial metadata due to coalescing, thus write tag:3 will come up here. - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking) .Expect(2, true) .Expect(3, true) @@ -523,7 +528,7 @@ TEST_P(AsyncEnd2endTest, SimpleClientStreamingWithCoalescingApi) { srv_stream.Read(&recv_request, tag(4)); - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get()); } else { Verifier(GetParam().disable_blocking) @@ -807,7 +812,7 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWAF) { // up until server read is initiated. For write of send_request smaller than // the flow control window size, the request can take the free ride with // initial metadata due to coalescing, thus write tag:3 will come up here. - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking) .Expect(2, true) .Expect(3, true) @@ -818,7 +823,7 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWAF) { srv_stream.Read(&recv_request, tag(4)); - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get()); } else { Verifier(GetParam().disable_blocking) @@ -875,7 +880,7 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWL) { // up until server read is initiated. For write of send_request smaller than // the flow control window size, the request can take the free ride with // initial metadata due to coalescing, thus write tag:3 will come up here. - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking) .Expect(2, true) .Expect(3, true) @@ -886,7 +891,7 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWL) { srv_stream.Read(&recv_request, tag(4)); - if (GetParam().message_content.length() < 65536) { + if (GetParam().message_content.length() < 65536 || GetParam().inproc) { Verifier(GetParam().disable_blocking).Expect(4, true).Verify(cq_.get()); } else { Verifier(GetParam().disable_blocking) @@ -1223,7 +1228,9 @@ TEST_P(AsyncEnd2endTest, UnimplementedRpc) { auto channel_creds = GetCredentialsProvider()->GetChannelCredentials( GetParam().credentials_type, &args); std::shared_ptr<Channel> channel = - CreateCustomChannel(server_address_.str(), channel_creds, args); + !(GetParam().inproc) + ? CreateCustomChannel(server_address_.str(), channel_creds, args) + : server_->InProcessChannel(args); std::unique_ptr<grpc::testing::UnimplementedEchoService::Stub> stub; stub = grpc::testing::UnimplementedEchoService::NewStub(channel); EchoRequest send_request; @@ -1634,13 +1641,17 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { // This is expected to succeed in all cases cli_stream->WritesDone(tag(7)); verif.Expect(7, true); - got_tag = verif.Next(cq_.get(), ignore_cq_result); + // TODO(vjpai): Consider whether the following is too flexible + // or whether it should just be reset to ignore_cq_result + bool ignore_cq_wd_result = + ignore_cq_result || (server_try_cancel == CANCEL_BEFORE_PROCESSING); + got_tag = verif.Next(cq_.get(), ignore_cq_wd_result); GPR_ASSERT((got_tag == 7) || (got_tag == 11 && want_done_tag)); if (got_tag == 11) { EXPECT_TRUE(srv_ctx.IsCancelled()); want_done_tag = false; // Now get the other entry that we were waiting on - EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_result), 7); + EXPECT_EQ(verif.Next(cq_.get(), ignore_cq_wd_result), 7); } // This is expected to fail in all cases i.e for all values of @@ -1732,8 +1743,14 @@ std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking, std::vector<grpc::string> credentials_types; std::vector<grpc::string> messages; - if (GetCredentialsProvider()->GetChannelCredentials(kInsecureCredentialsType, - nullptr) != nullptr) { + auto insec_ok = [] { + // Only allow insecure credentials type when it is registered with the + // provider. User may create providers that do not have insecure. + return GetCredentialsProvider()->GetChannelCredentials( + kInsecureCredentialsType, nullptr) != nullptr; + }; + + if (insec_ok()) { credentials_types.push_back(kInsecureCredentialsType); } auto sec_list = GetCredentialsProvider()->GetSecureCredentialsTypeList(); @@ -1755,14 +1772,19 @@ std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking, // TODO (sreek) Renable tests with health check service after the issue // https://github.com/grpc/grpc/issues/11223 is resolved for (auto health_check_service : {false}) { - for (auto cred = credentials_types.begin(); cred != credentials_types.end(); - ++cred) { - for (auto msg = messages.begin(); msg != messages.end(); msg++) { - scenarios.emplace_back(false, *cred, health_check_service, *msg); + for (auto msg = messages.begin(); msg != messages.end(); msg++) { + for (auto cred = credentials_types.begin(); + cred != credentials_types.end(); ++cred) { + scenarios.emplace_back(false, false, *cred, health_check_service, *msg); if (test_disable_blocking) { - scenarios.emplace_back(true, *cred, health_check_service, *msg); + scenarios.emplace_back(true, false, *cred, health_check_service, + *msg); } } + if (insec_ok()) { + scenarios.emplace_back(false, true, kInsecureCredentialsType, + health_check_service, *msg); + } } } return scenarios; diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index d72dda3f59..8d12971bc1 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -193,10 +193,11 @@ class TestServiceImplDupPkg class TestScenario { public: - TestScenario(bool proxy, const grpc::string& creds_type) - : use_proxy(proxy), credentials_type(creds_type) {} + TestScenario(bool proxy, bool inproc_stub, const grpc::string& creds_type) + : use_proxy(proxy), inproc(inproc_stub), credentials_type(creds_type) {} void Log() const; bool use_proxy; + bool inproc; // Although the below grpc::string is logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) // manage vector insertion using a copy constructor @@ -206,8 +207,9 @@ class TestScenario { static std::ostream& operator<<(std::ostream& out, const TestScenario& scenario) { return out << "TestScenario{use_proxy=" - << (scenario.use_proxy ? "true" : "false") << ", credentials='" - << scenario.credentials_type << "'}"; + << (scenario.use_proxy ? "true" : "false") + << ", inproc=" << (scenario.inproc ? "true" : "false") + << ", credentials='" << scenario.credentials_type << "'}"; } void TestScenario::Log() const { @@ -273,7 +275,13 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { args.SetUserAgentPrefix(user_agent_prefix_); } args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test"); - channel_ = CreateCustomChannel(server_address_.str(), channel_creds, args); + + if (!GetParam().inproc) { + channel_ = + CreateCustomChannel(server_address_.str(), channel_creds, args); + } else { + channel_ = server_->InProcessChannel(args); + } } void ResetStub() { @@ -633,6 +641,10 @@ TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { } TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { + // User-Agent is an HTTP header for HTTP transports only + if (GetParam().inproc) { + return; + } user_agent_prefix_ = "custom_prefix"; ResetStub(); EchoRequest request; @@ -1065,6 +1077,10 @@ TEST_P(End2endTest, SimultaneousReadWritesDone) { } TEST_P(End2endTest, ChannelState) { + if (GetParam().inproc) { + return; + } + ResetStub(); // Start IDLE EXPECT_EQ(GRPC_CHANNEL_IDLE, channel_->GetState(false)); @@ -1088,7 +1104,8 @@ TEST_P(End2endTest, ChannelState) { // Takes 10s. TEST_P(End2endTest, ChannelStateTimeout) { - if (GetParam().credentials_type != kInsecureCredentialsType) { + if ((GetParam().credentials_type != kInsecureCredentialsType) || + GetParam().inproc) { return; } int port = grpc_pick_unused_port_or_die(); @@ -1669,51 +1686,56 @@ TEST_P(ResourceQuotaEnd2endTest, SimpleRequest) { std::vector<TestScenario> CreateTestScenarios(bool use_proxy, bool test_insecure, - bool test_secure) { + bool test_secure, + bool test_inproc) { std::vector<TestScenario> scenarios; std::vector<grpc::string> credentials_types; if (test_secure) { credentials_types = GetCredentialsProvider()->GetSecureCredentialsTypeList(); } - if (test_insecure) { - // Only add insecure credentials type when it is registered with the + auto insec_ok = [] { + // Only allow insecure credentials type when it is registered with the // provider. User may create providers that do not have insecure. - if (GetCredentialsProvider()->GetChannelCredentials( - kInsecureCredentialsType, nullptr) != nullptr) { - credentials_types.push_back(kInsecureCredentialsType); - } + return GetCredentialsProvider()->GetChannelCredentials( + kInsecureCredentialsType, nullptr) != nullptr; + }; + if (test_insecure && insec_ok()) { + credentials_types.push_back(kInsecureCredentialsType); } GPR_ASSERT(!credentials_types.empty()); for (auto it = credentials_types.begin(); it != credentials_types.end(); ++it) { - scenarios.emplace_back(false, *it); + scenarios.emplace_back(false, false, *it); if (use_proxy) { - scenarios.emplace_back(true, *it); + scenarios.emplace_back(true, false, *it); } } + if (test_inproc && insec_ok()) { + scenarios.emplace_back(false, true, kInsecureCredentialsType); + } return scenarios; } INSTANTIATE_TEST_CASE_P(End2end, End2endTest, ::testing::ValuesIn(CreateTestScenarios(false, true, - true))); + true, true))); INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest, ::testing::ValuesIn(CreateTestScenarios(false, true, - true))); + true, true))); INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest, ::testing::ValuesIn(CreateTestScenarios(true, true, - true))); + true, false))); INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest, ::testing::ValuesIn(CreateTestScenarios(false, false, - true))); + true, false))); INSTANTIATE_TEST_CASE_P(ResourceQuotaEnd2end, ResourceQuotaEnd2endTest, ::testing::ValuesIn(CreateTestScenarios(false, true, - true))); + true, true))); } // namespace } // namespace testing diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 542df00fb4..f990a7ed9d 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -151,16 +151,6 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { std::mutex mu_; }; -class TestServiceImplDupPkg - : public ::grpc::testing::duplicate::EchoTestService::Service { - public: - Status Echo(ServerContext* context, const EchoRequest* request, - EchoResponse* response) override { - response->set_message("no package"); - return Status::OK; - } -}; - template <class Service> class CommonStressTest { public: @@ -168,63 +158,92 @@ class CommonStressTest { virtual ~CommonStressTest() {} virtual void SetUp() = 0; virtual void TearDown() = 0; - void ResetStub() { - std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureChannelCredentials()); - stub_ = grpc::testing::EchoTestService::NewStub(channel); - } + virtual void ResetStub() = 0; grpc::testing::EchoTestService::Stub* GetStub() { return stub_.get(); } protected: - void SetUpStart(ServerBuilder* builder, Service* service) { - int port = grpc_pick_unused_port_or_die(); - server_address_ << "localhost:" << port; - // Setup server - builder->AddListeningPort(server_address_.str(), - InsecureServerCredentials()); + std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; + std::unique_ptr<Server> server_; + + virtual void SetUpStart(ServerBuilder* builder, Service* service) = 0; + void SetUpStartCommon(ServerBuilder* builder, Service* service) { builder->RegisterService(service); builder->SetMaxMessageSize( kMaxMessageSize_); // For testing max message size. - builder->RegisterService(&dup_pkg_service_); } void SetUpEnd(ServerBuilder* builder) { server_ = builder->BuildAndStart(); } void TearDownStart() { server_->Shutdown(); } void TearDownEnd() {} private: - std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; - std::unique_ptr<Server> server_; - std::ostringstream server_address_; const int kMaxMessageSize_; - TestServiceImplDupPkg dup_pkg_service_; }; -class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> { +template <class Service> +class CommonStressTestInsecure : public CommonStressTest<Service> { + public: + void ResetStub() override { + std::shared_ptr<Channel> channel = + CreateChannel(server_address_.str(), InsecureChannelCredentials()); + this->stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + protected: + void SetUpStart(ServerBuilder* builder, Service* service) override { + int port = grpc_pick_unused_port_or_die(); + this->server_address_ << "localhost:" << port; + // Setup server + builder->AddListeningPort(server_address_.str(), + InsecureServerCredentials()); + this->SetUpStartCommon(builder, service); + } + + private: + std::ostringstream server_address_; +}; + +template <class Service> +class CommonStressTestInproc : public CommonStressTest<Service> { + public: + void ResetStub() override { + ChannelArguments args; + std::shared_ptr<Channel> channel = this->server_->InProcessChannel(args); + this->stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + protected: + void SetUpStart(ServerBuilder* builder, Service* service) override { + this->SetUpStartCommon(builder, service); + } +}; + +template <class BaseClass> +class CommonStressTestSyncServer : public BaseClass { public: void SetUp() override { ServerBuilder builder; - SetUpStart(&builder, &service_); - SetUpEnd(&builder); + this->SetUpStart(&builder, &service_); + this->SetUpEnd(&builder); } void TearDown() override { - TearDownStart(); - TearDownEnd(); + this->TearDownStart(); + this->TearDownEnd(); } private: TestServiceImpl service_; }; -class CommonStressTestAsyncServer - : public CommonStressTest<grpc::testing::EchoTestService::AsyncService> { +template <class BaseClass> +class CommonStressTestAsyncServer : public BaseClass { public: CommonStressTestAsyncServer() : contexts_(kNumAsyncServerThreads * 100) {} void SetUp() override { shutting_down_ = false; ServerBuilder builder; - SetUpStart(&builder, &service_); + this->SetUpStart(&builder, &service_); cq_ = builder.AddCompletionQueue(); - SetUpEnd(&builder); + this->SetUpEnd(&builder); for (int i = 0; i < kNumAsyncServerThreads * 100; i++) { RefreshContext(i); } @@ -236,7 +255,7 @@ class CommonStressTestAsyncServer void TearDown() override { { std::unique_lock<std::mutex> l(mu_); - TearDownStart(); + this->TearDownStart(); shutting_down_ = true; cq_->Shutdown(); } @@ -249,7 +268,7 @@ class CommonStressTestAsyncServer bool ignored_ok; while (cq_->Next(&ignored_tag, &ignored_ok)) ; - TearDownEnd(); + this->TearDownEnd(); } private: @@ -332,8 +351,13 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { } } -typedef ::testing::Types<CommonStressTestSyncServer, - CommonStressTestAsyncServer> +typedef ::testing::Types< + CommonStressTestSyncServer<CommonStressTestInsecure<TestServiceImpl>>, + CommonStressTestSyncServer<CommonStressTestInproc<TestServiceImpl>>, + CommonStressTestAsyncServer< + CommonStressTestInsecure<grpc::testing::EchoTestService::AsyncService>>, + CommonStressTestAsyncServer< + CommonStressTestInproc<grpc::testing::EchoTestService::AsyncService>>> CommonTypes; TYPED_TEST_CASE(End2endTest, CommonTypes); TYPED_TEST(End2endTest, ThreadStress) { diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index 0de5a6f4da..9123bd929e 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -88,13 +88,22 @@ grpc_cc_library( ], ) -grpc_cc_binary( - name = "interop_client", +grpc_cc_library( + name = "interop_client_main", srcs = [ "client.cc", ], + language = "C++", deps = [ ":client_helper_lib", + ], +) + +grpc_cc_binary( + name = "interop_client", + language = "C++", + deps = [ + ":interop_client_main", "//:grpc++", ], ) diff --git a/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc b/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc index f420bd7421..0712a40018 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc @@ -414,24 +414,34 @@ BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcessCHTTP2, NoOpMutator, ->Apply(StreamingPingPongArgs); BENCHMARK_TEMPLATE(BM_StreamingPingPong, TCP, NoOpMutator, NoOpMutator) ->Apply(StreamingPingPongArgs); +BENCHMARK_TEMPLATE(BM_StreamingPingPong, InProcess, NoOpMutator, NoOpMutator) + ->Apply(StreamingPingPongArgs); BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcessCHTTP2, NoOpMutator, NoOpMutator) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, TCP, NoOpMutator, NoOpMutator) ->Range(0, 128 * 1024 * 1024); +BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, InProcess, NoOpMutator, + NoOpMutator) + ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcessCHTTP2, NoOpMutator, NoOpMutator) ->Apply(StreamingPingPongArgs); BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinTCP, NoOpMutator, NoOpMutator) ->Apply(StreamingPingPongArgs); +BENCHMARK_TEMPLATE(BM_StreamingPingPong, MinInProcess, NoOpMutator, NoOpMutator) + ->Apply(StreamingPingPongArgs); BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcessCHTTP2, NoOpMutator, NoOpMutator) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinTCP, NoOpMutator, NoOpMutator) ->Range(0, 128 * 1024 * 1024); +BENCHMARK_TEMPLATE(BM_StreamingPingPongMsgs, MinInProcess, NoOpMutator, + NoOpMutator) + ->Range(0, 128 * 1024 * 1024); // Generate Args for StreamingPingPongWithCoalescingApi benchmarks. Currently // generates args for only "small streams" (i.e streams with 0, 1 or 2 messages) @@ -459,6 +469,12 @@ BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcessCHTTP2, BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcessCHTTP2, NoOpMutator, NoOpMutator) ->Apply(StreamingPingPongWithCoalescingApiArgs); +BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, InProcess, + NoOpMutator, NoOpMutator) + ->Apply(StreamingPingPongWithCoalescingApiArgs); +BENCHMARK_TEMPLATE(BM_StreamingPingPongWithCoalescingApi, MinInProcess, + NoOpMutator, NoOpMutator) + ->Apply(StreamingPingPongWithCoalescingApiArgs); } // namespace testing } // namespace grpc diff --git a/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc b/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc index fc2d67ff11..6fbf9da0ad 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc @@ -173,6 +173,8 @@ BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, TCP) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, UDS) ->Range(0, 128 * 1024 * 1024); +BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, InProcess) + ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, SockPair) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, InProcessCHTTP2) @@ -181,16 +183,20 @@ BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, TCP) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, UDS) ->Range(0, 128 * 1024 * 1024); +BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, InProcess) + ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, SockPair) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, InProcessCHTTP2) ->Range(0, 128 * 1024 * 1024); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, MinTCP)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, MinUDS)->Arg(0); +BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, MinInProcess)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, MinSockPair)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamClientToServer, MinInProcessCHTTP2)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, MinTCP)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, MinUDS)->Arg(0); +BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, MinInProcess)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, MinSockPair)->Arg(0); BENCHMARK_TEMPLATE(BM_PumpStreamServerToClient, MinInProcessCHTTP2)->Arg(0); diff --git a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc index ee2d5ec7f4..9af751245f 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc @@ -132,6 +132,10 @@ BENCHMARK_TEMPLATE(BM_UnaryPingPong, UDS, NoOpMutator, NoOpMutator) ->Args({0, 0}); BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinUDS, NoOpMutator, NoOpMutator) ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, NoOpMutator) + ->Apply(SweepSizesArgs); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinInProcess, NoOpMutator, NoOpMutator) + ->Apply(SweepSizesArgs); BENCHMARK_TEMPLATE(BM_UnaryPingPong, SockPair, NoOpMutator, NoOpMutator) ->Args({0, 0}); BENCHMARK_TEMPLATE(BM_UnaryPingPong, MinSockPair, NoOpMutator, NoOpMutator) @@ -191,6 +195,56 @@ BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>) ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<10>, 1>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<31>, 1>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<100>, 1>, + NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<10>, 2>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<31>, 2>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomBinaryMetadata<100>, 2>, + NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomBinaryMetadata<10>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomBinaryMetadata<31>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomBinaryMetadata<100>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomAsciiMetadata<10>, 1>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomAsciiMetadata<31>, 1>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, + Client_AddMetadata<RandomAsciiMetadata<100>, 1>, NoOpMutator) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomAsciiMetadata<10>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomAsciiMetadata<31>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomAsciiMetadata<100>, 1>) + ->Args({0, 0}); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcess, NoOpMutator, + Server_AddInitialMetadata<RandomAsciiMetadata<10>, 100>) + ->Args({0, 0}); } // namespace testing } // namespace grpc diff --git a/test/cpp/microbenchmarks/fullstack_fixtures.h b/test/cpp/microbenchmarks/fullstack_fixtures.h index 2320086afc..5477b860b4 100644 --- a/test/cpp/microbenchmarks/fullstack_fixtures.h +++ b/test/cpp/microbenchmarks/fullstack_fixtures.h @@ -66,14 +66,21 @@ class FullstackFixture : public BaseFixture { FullstackFixture(Service* service, const FixtureConfiguration& config, const grpc::string& address) { ServerBuilder b; - b.AddListeningPort(address, InsecureServerCredentials()); + if (address.length() > 0) { + b.AddListeningPort(address, InsecureServerCredentials()); + } cq_ = b.AddCompletionQueue(true); b.RegisterService(service); config.ApplyCommonServerBuilderConfig(&b); server_ = b.BuildAndStart(); ChannelArguments args; config.ApplyCommonChannelArguments(&args); - channel_ = CreateCustomChannel(address, InsecureChannelCredentials(), args); + if (address.length() > 0) { + channel_ = + CreateCustomChannel(address, InsecureChannelCredentials(), args); + } else { + channel_ = server_->InProcessChannel(args); + } } virtual ~FullstackFixture() { @@ -139,6 +146,15 @@ class UDS : public FullstackFixture { } }; +class InProcess : public FullstackFixture { + public: + InProcess(Service* service, + const FixtureConfiguration& fixture_configuration = + FixtureConfiguration()) + : FullstackFixture(service, fixture_configuration, "") {} + ~InProcess() {} +}; + class EndpointPairFixture : public BaseFixture { public: EndpointPairFixture(Service* service, grpc_endpoint_pair endpoints, @@ -279,6 +295,7 @@ class MinStackize : public Base { typedef MinStackize<TCP> MinTCP; typedef MinStackize<UDS> MinUDS; +typedef MinStackize<InProcess> MinInProcess; typedef MinStackize<SockPair> MinSockPair; typedef MinStackize<InProcessCHTTP2> MinInProcessCHTTP2; diff --git a/test/cpp/qps/OWNERS b/test/cpp/qps/OWNERS deleted file mode 100644 index 8ccea9ad9b..0000000000 --- a/test/cpp/qps/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -@vjpai - diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index f47f378a98..6c4d92e859 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -89,9 +89,7 @@ class ClientRequestCreator<ByteBuffer> { if (payload_config.has_bytebuf_params()) { std::unique_ptr<char[]> buf( new char[payload_config.bytebuf_params().req_size()]); - grpc_slice s = grpc_slice_from_copied_buffer( - buf.get(), payload_config.bytebuf_params().req_size()); - Slice slice(s, Slice::STEAL_REF); + Slice slice(buf.get(), payload_config.bytebuf_params().req_size()); *req = ByteBuffer(&slice, 1); } else { GPR_ASSERT(false); // not appropriate for this specialization diff --git a/test/cpp/server/BUILD b/test/cpp/server/BUILD new file mode 100644 index 0000000000..512241e350 --- /dev/null +++ b/test/cpp/server/BUILD @@ -0,0 +1,43 @@ +# 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. + +licenses(["notice"]) # Apache v2 + +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_cc_library", "grpc_cc_binary") + +grpc_cc_test( + name = "server_builder_test", + srcs = ["server_builder_test.cc"], + deps = [ + "//:grpc++", + "//src/proto/grpc/testing:echo_proto", + "//test/core/util:grpc_test_util", + ], + external_deps = [ + "gtest", + ], +) + +grpc_cc_test( + name = "server_request_call_test", + srcs = ["server_request_call_test.cc"], + deps = [ + "//:grpc++", + "//src/proto/grpc/testing:echo_proto", + "//test/core/util:grpc_test_util", + ], + external_deps = [ + "gtest", + ], +) diff --git a/test/cpp/server/server_request_call_test.cc b/test/cpp/server/server_request_call_test.cc new file mode 100644 index 0000000000..1c64ddfc67 --- /dev/null +++ b/test/cpp/server/server_request_call_test.cc @@ -0,0 +1,162 @@ +/* + * + * 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 <thread> + +#include <grpc++/impl/codegen/config.h> +#include <gtest/gtest.h> + +#include <grpc++/server.h> +#include <grpc++/server_builder.h> + +#include <grpc++/create_channel.h> +#include <grpc++/security/credentials.h> + +#include <grpc/support/log.h> + +#include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "test/core/util/port.h" + +namespace grpc { +namespace { + +TEST(ServerRequestCallTest, ShortDeadlineDoesNotCauseOkayFalse) { + std::mutex mu; + bool shutting_down = false; + + // grpc server config. + std::ostringstream s; + int p = grpc_pick_unused_port_or_die(); + s << "[::1]:" << p; + const string address = s.str(); + testing::EchoTestService::AsyncService service; + ServerBuilder builder; + builder.AddListeningPort(address, InsecureServerCredentials()); + auto cq = builder.AddCompletionQueue(); + builder.RegisterService(&service); + auto server = builder.BuildAndStart(); + + // server thread. + std::thread t([address, &service, &cq, &mu, &shutting_down] { + for (int n = 0; true; n++) { + ServerContext ctx; + testing::EchoRequest req; + ServerAsyncResponseWriter<testing::EchoResponse> responder(&ctx); + + // if shutting down, don't enqueue a new request. + { + std::lock_guard<std::mutex> lock(mu); + if (!shutting_down) { + service.RequestEcho(&ctx, &req, &responder, cq.get(), cq.get(), + (void*)1); + } + } + + bool ok; + void* tag; + if (!cq->Next(&tag, &ok)) { + break; + } + + EXPECT_EQ((void*)1, tag); + // If not shutting down, ok must be true for new requests. + { + std::lock_guard<std::mutex> lock(mu); + if (!shutting_down && !ok) { + gpr_log(GPR_INFO, "!ok on request %d", n); + abort(); + } + if (shutting_down && !ok) { + // Failed connection due to shutdown, continue flushing the CQ. + continue; + } + } + + // Send a simple response after a small delay that would ensure the client + // deadline is exceeded. + gpr_log(GPR_INFO, "Got request %d", n); + testing::EchoResponse response; + response.set_message("foobar"); + // A bit of sleep to make sure the deadline elapses. + gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), + gpr_time_from_millis(50, GPR_TIMESPAN))); + { + std::lock_guard<std::mutex> lock(mu); + if (shutting_down) { + gpr_log(GPR_INFO, + "shut down while processing call, not calling Finish()"); + // Continue flushing the CQ. + continue; + } + gpr_log(GPR_INFO, "Finishing request %d", n); + responder.Finish(response, grpc::Status::OK, (void*)2); + if (!cq->Next(&tag, &ok)) { + break; + } + EXPECT_EQ((void*)2, tag); + } + } + }); + + auto stub = testing::EchoTestService::NewStub( + CreateChannel(address, InsecureChannelCredentials())); + + for (int i = 0; i < 100; i++) { + gpr_log(GPR_INFO, "Sending %d.", i); + testing::EchoRequest request; + + ///////// + // Comment out the following line to get ok=false due to invalid request. + // Otherwise, ok=false due to deadline being exceeded. + ///////// + request.set_message("foobar"); + + // A simple request with a short deadline. The server will always exceed the + // deadline, whether due to the sleep or because the server was unable to + // even fetch the request from the CQ before the deadline elapsed. + testing::EchoResponse response; + ::grpc::ClientContext ctx; + ctx.set_fail_fast(false); + ctx.set_deadline(std::chrono::system_clock::now() + + std::chrono::milliseconds(1)); + grpc::Status status = stub->Echo(&ctx, request, &response); + EXPECT_EQ(DEADLINE_EXCEEDED, status.error_code()); + gpr_log(GPR_INFO, "Success."); + } + gpr_log(GPR_INFO, "Done sending RPCs."); + + // Shut down everything properly. + gpr_log(GPR_INFO, "Shutting down."); + { + std::lock_guard<std::mutex> lock(mu); + shutting_down = true; + } + server->Shutdown(); + cq->Shutdown(); + server->Wait(); + + t.join(); +} + +} // namespace +} // namespace grpc + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/test/cpp/util/byte_buffer_proto_helper.cc b/test/cpp/util/byte_buffer_proto_helper.cc index 22dd074fe9..bb5162f86e 100644 --- a/test/cpp/util/byte_buffer_proto_helper.cc +++ b/test/cpp/util/byte_buffer_proto_helper.cc @@ -36,8 +36,7 @@ std::unique_ptr<ByteBuffer> SerializeToByteBuffer( grpc::protobuf::Message* message) { grpc::string buf; message->SerializeToString(&buf); - grpc_slice s = grpc_slice_from_copied_string(buf.c_str()); - Slice slice(s, Slice::STEAL_REF); + Slice slice(buf); return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1)); } diff --git a/test/cpp/util/byte_buffer_test.cc b/test/cpp/util/byte_buffer_test.cc index 6c077ddb2c..cac01a7307 100644 --- a/test/cpp/util/byte_buffer_test.cc +++ b/test/cpp/util/byte_buffer_test.cc @@ -34,33 +34,30 @@ const char* kContent2 = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy world"; class ByteBufferTest : public ::testing::Test {}; TEST_F(ByteBufferTest, CreateFromSingleSlice) { - grpc_slice hello = grpc_slice_from_copied_string(kContent1); - Slice s(hello, Slice::STEAL_REF); + Slice s(kContent1); ByteBuffer buffer(&s, 1); + EXPECT_EQ(strlen(kContent1), buffer.Length()); } TEST_F(ByteBufferTest, CreateFromVector) { - grpc_slice hello = grpc_slice_from_copied_string(kContent1); - grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; - slices.push_back(Slice(hello, Slice::STEAL_REF)); - slices.push_back(Slice(world, Slice::STEAL_REF)); + slices.emplace_back(kContent1); + slices.emplace_back(kContent2); ByteBuffer buffer(&slices[0], 2); + EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); } TEST_F(ByteBufferTest, Clear) { - grpc_slice hello = grpc_slice_from_copied_string(kContent1); - Slice s(hello, Slice::STEAL_REF); + Slice s(kContent1); ByteBuffer buffer(&s, 1); buffer.Clear(); + EXPECT_EQ(static_cast<size_t>(0), buffer.Length()); } TEST_F(ByteBufferTest, Length) { - grpc_slice hello = grpc_slice_from_copied_string(kContent1); - grpc_slice world = grpc_slice_from_copied_string(kContent2); std::vector<Slice> slices; - slices.push_back(Slice(hello, Slice::STEAL_REF)); - slices.push_back(Slice(world, Slice::STEAL_REF)); + slices.emplace_back(kContent1); + slices.emplace_back(kContent2); ByteBuffer buffer(&slices[0], 2); EXPECT_EQ(strlen(kContent1) + strlen(kContent2), buffer.Length()); } diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index fb6d76bb90..c3220efa54 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -119,8 +119,7 @@ void CliCall::WritesDone() { } void CliCall::WriteAndWait(const grpc::string& request) { - grpc_slice s = grpc_slice_from_copied_string(request.c_str()); - grpc::Slice req_slice(s, grpc::Slice::STEAL_REF); + grpc::Slice req_slice(request); grpc::ByteBuffer send_buffer(&req_slice, 1); gpr_mu_lock(&write_mu_); diff --git a/test/cpp/util/slice_test.cc b/test/cpp/util/slice_test.cc index 0f80003580..9e3329fab0 100644 --- a/test/cpp/util/slice_test.cc +++ b/test/cpp/util/slice_test.cc @@ -28,6 +28,9 @@ const char* kContent = "hello xxxxxxxxxxxxxxxxxxxx world"; class SliceTest : public ::testing::Test { protected: + void CheckSliceSize(const Slice& s, const grpc::string& content) { + EXPECT_EQ(content.size(), s.size()); + } void CheckSlice(const Slice& s, const grpc::string& content) { EXPECT_EQ(content.size(), s.size()); EXPECT_EQ(content, @@ -35,6 +38,31 @@ class SliceTest : public ::testing::Test { } }; +TEST_F(SliceTest, Empty) { + Slice empty_slice; + CheckSlice(empty_slice, ""); +} + +TEST_F(SliceTest, Sized) { + Slice sized_slice(strlen(kContent)); + CheckSliceSize(sized_slice, kContent); +} + +TEST_F(SliceTest, String) { + Slice spp(kContent); + CheckSlice(spp, kContent); +} + +TEST_F(SliceTest, Buf) { + Slice spp(kContent, strlen(kContent)); + CheckSlice(spp, kContent); +} + +TEST_F(SliceTest, StaticBuf) { + Slice spp(kContent, strlen(kContent), Slice::STATIC_SLICE); + CheckSlice(spp, kContent); +} + TEST_F(SliceTest, Steal) { grpc_slice s = grpc_slice_from_copied_string(kContent); Slice spp(s, Slice::STEAL_REF); @@ -48,11 +76,6 @@ TEST_F(SliceTest, Add) { CheckSlice(spp, kContent); } -TEST_F(SliceTest, Empty) { - Slice empty_slice; - CheckSlice(empty_slice, ""); -} - TEST_F(SliceTest, Cslice) { grpc_slice s = grpc_slice_from_copied_string(kContent); Slice spp(s, Slice::STEAL_REF); diff --git a/test/distrib/node/OWNERS b/test/distrib/node/OWNERS deleted file mode 100644 index 567d1b6691..0000000000 --- a/test/distrib/node/OWNERS +++ /dev/null @@ -1 +0,0 @@ -@murgatroid99 |