diff options
author | 2016-02-22 21:41:31 -0800 | |
---|---|---|
committer | 2016-02-22 21:41:31 -0800 | |
commit | 6895168e0ac19699f2a1e35cbf094a5477f00ca7 (patch) | |
tree | 322191a335da99badc2411254499575533ba8bb5 /test/cpp/end2end | |
parent | b88e962d64495fd6e6896f1ffaff1def43bd95a5 (diff) | |
parent | 30e9de8099ead2ca6e6d2dcd14df6d3c808bed18 (diff) |
Merge github.com:grpc/grpc into filter-selection
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r-- | test/cpp/end2end/async_end2end_test.cc | 44 | ||||
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 69 |
2 files changed, 73 insertions, 40 deletions
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index a194c615cd..9ca3bf98f8 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -43,6 +43,7 @@ #include <grpc/grpc.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> +#include <grpc/support/tls.h> #include <gtest/gtest.h> #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" @@ -59,6 +60,8 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; +GPR_TLS_DECL(g_is_async_end2end_test); + namespace grpc { namespace testing { @@ -67,9 +70,11 @@ namespace { void* tag(int i) { return (void*)(intptr_t)i; } #ifdef GPR_POSIX_SOCKET -static int assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds, - int timeout) { - GPR_ASSERT(timeout == 0); +static int maybe_assert_non_blocking_poll(struct pollfd* pfds, nfds_t nfds, + int timeout) { + if (gpr_tls_get(&g_is_async_end2end_test)) { + GPR_ASSERT(timeout == 0); + } return poll(pfds, nfds, timeout); } @@ -86,21 +91,21 @@ class PollOverride { grpc_poll_function_type prev_; }; -class PollingCheckRegion : public PollOverride { +class PollingOverrider : public PollOverride { public: - explicit PollingCheckRegion(bool allow_blocking) - : PollOverride(allow_blocking ? poll : assert_non_blocking_poll) {} + explicit PollingOverrider(bool allow_blocking) + : PollOverride(allow_blocking ? poll : maybe_assert_non_blocking_poll) {} }; #else -class PollingCheckRegion { +class PollingOverrider { public: - explicit PollingCheckRegion(bool allow_blocking) {} + explicit PollingOverrider(bool allow_blocking) {} }; #endif -class Verifier : public PollingCheckRegion { +class Verifier { public: - explicit Verifier(bool spin) : PollingCheckRegion(!spin), spin_(spin) {} + explicit Verifier(bool spin) : spin_(spin) {} Verifier& Expect(int i, bool expect_ok) { expectations_[tag(i)] = expect_ok; return *this; @@ -183,6 +188,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { AsyncEnd2endTest() {} void SetUp() GRPC_OVERRIDE { + poll_overrider_.reset(new PollingOverrider(!GetParam())); + int port = grpc_pick_unused_port_or_die(); server_address_ << "localhost:" << port; @@ -193,6 +200,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { builder.RegisterService(&service_); cq_ = builder.AddCompletionQueue(); server_ = builder.BuildAndStart(); + + gpr_tls_set(&g_is_async_end2end_test, 1); } void TearDown() GRPC_OVERRIDE { @@ -202,6 +211,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { cq_->Shutdown(); while (cq_->Next(&ignored_tag, &ignored_ok)) ; + poll_overrider_.reset(); + gpr_tls_set(&g_is_async_end2end_test, 0); } void ResetStub() { @@ -249,6 +260,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> { std::unique_ptr<Server> server_; grpc::testing::EchoTestService::AsyncService service_; std::ostringstream server_address_; + + std::unique_ptr<PollingOverrider> poll_overrider_; }; TEST_P(AsyncEnd2endTest, SimpleRpc) { @@ -976,6 +989,10 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { if (server_try_cancel == CANCEL_AFTER_PROCESSING) { ServerTryCancel(&srv_ctx); + + // Client reads may fail bacause it is notified that the stream is + // cancelled. + ignore_cq_result = true; } // Client attemts to read the three messages from the server @@ -1087,7 +1104,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest { Verifier(GetParam()).Expect(7, true).Verify(cq_.get()); // This is expected to fail in all cases i.e for all values of - // server_try_cancel. This is becasue at this point, either there are no + // server_try_cancel. This is because at this point, either there are no // more msgs from the client (because client called WritesDone) or the RPC // is cancelled on the server srv_stream.Read(&recv_request, tag(8)); @@ -1164,6 +1181,9 @@ INSTANTIATE_TEST_CASE_P(AsyncEnd2endServerTryCancel, int main(int argc, char** argv) { grpc_test_init(argc, argv); + gpr_tls_init(&g_is_async_end2end_test); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int ret = RUN_ALL_TESTS(); + gpr_tls_destroy(&g_is_async_end2end_test); + return ret; } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index c8523847ab..ce8e4d2a10 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -51,11 +51,11 @@ #include "src/core/security/credentials.h" #include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" -#include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" #include "test/cpp/end2end/test_service_impl.h" #include "test/cpp/util/string_ref_helper.h" +#include "test/cpp/util/test_credentials_provider.h" using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; @@ -191,12 +191,14 @@ class TestServiceImplDupPkg class TestScenario { public: - TestScenario(bool proxy, bool tls) : use_proxy(proxy), use_tls(tls) {} + TestScenario(bool proxy, const grpc::string& creds_type) + : use_proxy(proxy), credentials_type(creds_type) {} void Log() const { - gpr_log(GPR_INFO, "Scenario: proxy %d, tls %d", use_proxy, use_tls); + gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy, + credentials_type.c_str()); } bool use_proxy; - bool use_tls; + const grpc::string credentials_type; }; class End2endTest : public ::testing::TestWithParam<TestScenario> { @@ -220,14 +222,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { server_address_ << "127.0.0.1:" << port; // Setup server ServerBuilder builder; - auto server_creds = InsecureServerCredentials(); - if (GetParam().use_tls) { - SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, - test_server1_cert}; - SslServerCredentialsOptions ssl_opts; - ssl_opts.pem_root_certs = ""; - ssl_opts.pem_key_cert_pairs.push_back(pkcp); - server_creds = SslServerCredentials(ssl_opts); + auto server_creds = GetServerCredentials(GetParam().credentials_type); + if (GetParam().credentials_type != kInsecureCredentialsType) { server_creds->SetAuthMetadataProcessor(processor); } builder.AddListeningPort(server_address_.str(), server_creds); @@ -246,12 +242,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { } EXPECT_TRUE(is_server_started_); ChannelArguments args; - auto channel_creds = InsecureChannelCredentials(); - if (GetParam().use_tls) { - SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; - args.SetSslTargetNameOverride("foo.test.google.fr"); - channel_creds = SslCredentials(ssl_opts); - } + auto channel_creds = + GetChannelCredentials(GetParam().credentials_type, &args); if (!user_agent_prefix_.empty()) { args.SetUserAgentPrefix(user_agent_prefix_); } @@ -941,7 +933,7 @@ TEST_P(End2endTest, ChannelState) { // Takes 10s. TEST_P(End2endTest, ChannelStateTimeout) { - if (GetParam().use_tls) { + if (GetParam().credentials_type != kInsecureCredentialsType) { return; } int port = grpc_pick_unused_port_or_die(); @@ -1150,7 +1142,7 @@ class SecureEnd2endTest : public End2endTest { protected: SecureEnd2endTest() { GPR_ASSERT(!GetParam().use_proxy); - GPR_ASSERT(GetParam().use_tls); + GPR_ASSERT(GetParam().credentials_type != kInsecureCredentialsType); } }; @@ -1373,21 +1365,42 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) { EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2])); } +std::vector<TestScenario> CreateTestScenarios(bool use_proxy, + bool test_insecure, + bool test_secure) { + std::vector<TestScenario> scenarios; + std::vector<grpc::string> credentials_types; + if (test_secure) { + credentials_types = GetSecureCredentialsTypeList(); + } + if (test_insecure) { + credentials_types.push_back(kInsecureCredentialsType); + } + for (auto it = credentials_types.begin(); it != credentials_types.end(); + ++it) { + scenarios.push_back(TestScenario(false, *it)); + if (use_proxy) { + scenarios.push_back(TestScenario(true, *it)); + } + } + return scenarios; +} + INSTANTIATE_TEST_CASE_P(End2end, End2endTest, - ::testing::Values(TestScenario(false, false), - TestScenario(false, true))); + ::testing::ValuesIn(CreateTestScenarios(false, true, + true))); INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest, - ::testing::Values(TestScenario(false, false))); + ::testing::ValuesIn(CreateTestScenarios(false, true, + false))); INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest, - ::testing::Values(TestScenario(false, false), - TestScenario(false, true), - TestScenario(true, false), - TestScenario(true, true))); + ::testing::ValuesIn(CreateTestScenarios(true, true, + true))); INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest, - ::testing::Values(TestScenario(false, true))); + ::testing::ValuesIn(CreateTestScenarios(false, false, + true))); } // namespace } // namespace testing |