diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/end2end/fixtures/inproc.c | 96 | ||||
-rwxr-xr-x | test/core/end2end/gen_build_yaml.py | 47 | ||||
-rwxr-xr-x | test/core/end2end/generate_tests.bzl | 55 | ||||
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 60 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 62 | ||||
-rw-r--r-- | test/cpp/end2end/thread_stress_test.cc | 102 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack_streaming_ping_pong.cc | 16 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack_streaming_pump.cc | 6 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_fullstack_unary_ping_pong.cc | 54 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/fullstack_fixtures.h | 21 |
10 files changed, 407 insertions, 112 deletions
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/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/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; |