aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-07-17 16:02:15 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-07-17 16:02:15 -0700
commit6016e260ca5d36408a3ae23db3c44481ee4c8427 (patch)
tree7dc0825c12b7c5eec567a833327b23706ce0363f /test/cpp
parent211e65be3cb1f4b6f7184c1945d8284905f79968 (diff)
parente9881bbaf3d53aa80099c42c80fb3331ff38270a (diff)
Merge branch 'master' of github.com:grpc/grpc into str_join_with_sep
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/common/auth_property_iterator_test.cc101
-rw-r--r--test/cpp/common/secure_auth_context_test.cc46
-rw-r--r--test/cpp/end2end/client_crash_test.cc3
-rw-r--r--test/cpp/end2end/end2end_test.cc17
-rw-r--r--test/cpp/end2end/mock_test.cc4
-rw-r--r--test/cpp/end2end/server_crash_test.cc19
-rw-r--r--test/cpp/end2end/thread_stress_test.cc12
-rw-r--r--test/cpp/interop/client.cc5
-rw-r--r--test/cpp/interop/interop_client.cc21
-rw-r--r--test/cpp/interop/interop_client.h1
-rw-r--r--test/cpp/interop/server.cc12
-rw-r--r--test/cpp/interop/server_helper.cc13
-rw-r--r--test/cpp/interop/server_helper.h13
-rw-r--r--test/cpp/qps/driver.cc7
-rw-r--r--test/cpp/qps/server_async.cc2
-rw-r--r--test/cpp/qps/server_sync.cc4
-rw-r--r--test/cpp/qps/worker.cc4
-rw-r--r--test/cpp/server/fixed_size_thread_pool_test.cc (renamed from test/cpp/server/thread_pool_test.cc)12
-rw-r--r--test/cpp/util/cli_call_test.cc4
-rw-r--r--test/cpp/util/time_test.cc11
20 files changed, 256 insertions, 55 deletions
diff --git a/test/cpp/common/auth_property_iterator_test.cc b/test/cpp/common/auth_property_iterator_test.cc
new file mode 100644
index 0000000000..3d983fa310
--- /dev/null
+++ b/test/cpp/common/auth_property_iterator_test.cc
@@ -0,0 +1,101 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc++/auth_context.h>
+#include <gtest/gtest.h>
+#include "src/cpp/common/secure_auth_context.h"
+#include "src/core/security/security_context.h"
+
+namespace grpc {
+namespace {
+
+class TestAuthPropertyIterator : public AuthPropertyIterator {
+ public:
+ TestAuthPropertyIterator() {}
+ TestAuthPropertyIterator(const grpc_auth_property* property,
+ const grpc_auth_property_iterator* iter)
+ : AuthPropertyIterator(property, iter) {}
+};
+
+class AuthPropertyIteratorTest : public ::testing::Test {
+ protected:
+ void SetUp() GRPC_OVERRIDE {
+ ctx_ = grpc_auth_context_create(NULL, 3);
+ ctx_->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi");
+ ctx_->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo");
+ ctx_->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar");
+ ctx_->peer_identity_property_name = ctx_->properties[0].name;
+ }
+ void TearDown() GRPC_OVERRIDE {
+ GRPC_AUTH_CONTEXT_UNREF(ctx_, "AuthPropertyIteratorTest");
+ }
+ grpc_auth_context* ctx_;
+
+};
+
+TEST_F(AuthPropertyIteratorTest, DefaultCtor) {
+ TestAuthPropertyIterator iter1;
+ TestAuthPropertyIterator iter2;
+ EXPECT_EQ(iter1, iter2);
+}
+
+TEST_F(AuthPropertyIteratorTest, GeneralTest) {
+ grpc_auth_property_iterator c_iter =
+ grpc_auth_context_property_iterator(ctx_);
+ const grpc_auth_property* property =
+ grpc_auth_property_iterator_next(&c_iter);
+ TestAuthPropertyIterator iter(property, &c_iter);
+ TestAuthPropertyIterator empty_iter;
+ EXPECT_FALSE(iter == empty_iter);
+ AuthProperty p0 = *iter;
+ ++iter;
+ AuthProperty p1 = *iter;
+ iter++;
+ AuthProperty p2 = *iter;
+ EXPECT_EQ("name", p0.first);
+ EXPECT_EQ("chapi", p0.second);
+ EXPECT_EQ("name", p1.first);
+ EXPECT_EQ("chapo", p1.second);
+ EXPECT_EQ("foo", p2.first);
+ EXPECT_EQ("bar", p2.second);
+ ++iter;
+ EXPECT_EQ(empty_iter, iter);
+}
+
+} // namespace
+} // namespace grpc
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/cpp/common/secure_auth_context_test.cc b/test/cpp/common/secure_auth_context_test.cc
index a1819dc4d6..f18a04178e 100644
--- a/test/cpp/common/secure_auth_context_test.cc
+++ b/test/cpp/common/secure_auth_context_test.cc
@@ -48,6 +48,7 @@ TEST_F(SecureAuthContextTest, EmptyContext) {
EXPECT_TRUE(context.GetPeerIdentityPropertyName().empty());
EXPECT_TRUE(context.FindPropertyValues("").empty());
EXPECT_TRUE(context.FindPropertyValues("whatever").empty());
+ EXPECT_TRUE(context.begin() == context.end());
}
TEST_F(SecureAuthContextTest, Properties) {
@@ -68,6 +69,51 @@ TEST_F(SecureAuthContextTest, Properties) {
EXPECT_EQ("bar", bar[0]);
}
+TEST_F(SecureAuthContextTest, Iterators) {
+ grpc_auth_context* ctx = grpc_auth_context_create(NULL, 3);
+ ctx->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi");
+ ctx->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo");
+ ctx->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar");
+ ctx->peer_identity_property_name = ctx->properties[0].name;
+
+ SecureAuthContext context(ctx);
+ AuthPropertyIterator iter = context.begin();
+ EXPECT_TRUE(context.end() != iter);
+ AuthProperty p0 = *iter;
+ ++iter;
+ AuthProperty p1 = *iter;
+ iter++;
+ AuthProperty p2 = *iter;
+ EXPECT_EQ("name", p0.first);
+ EXPECT_EQ("chapi", p0.second);
+ EXPECT_EQ("name", p1.first);
+ EXPECT_EQ("chapo", p1.second);
+ EXPECT_EQ("foo", p2.first);
+ EXPECT_EQ("bar", p2.second);
+ ++iter;
+ EXPECT_EQ(context.end(), iter);
+ // Range-based for loop test.
+ int i = 0;
+ for (auto p : context) {
+ switch (i++) {
+ case 0:
+ EXPECT_EQ("name", p.first);
+ EXPECT_EQ("chapi", p.second);
+ break;
+ case 1:
+ EXPECT_EQ("name", p.first);
+ EXPECT_EQ("chapo", p.second);
+ break;
+ case 2:
+ EXPECT_EQ("foo", p.first);
+ EXPECT_EQ("bar", p.second);
+ break;
+ default:
+ EXPECT_TRUE(0);
+ }
+ }
+}
+
} // namespace
} // namespace grpc
diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc
index 645226f375..906f124c05 100644
--- a/test/cpp/end2end/client_crash_test.cc
+++ b/test/cpp/end2end/client_crash_test.cc
@@ -31,13 +31,10 @@
*
*/
-#include <thread>
-
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 207dad5282..89d9d635af 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -35,7 +35,6 @@
#include <thread>
#include "src/core/security/credentials.h"
-#include "src/cpp/server/thread_pool.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
@@ -46,6 +45,7 @@
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -75,7 +75,7 @@ const char* kServerCancelAfterReads = "cancel_after_reads";
void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
EchoResponse* response) {
if (request->has_param() && request->param().echo_deadline()) {
- gpr_timespec deadline = gpr_inf_future;
+ gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
if (context->deadline() != system_clock::time_point::max()) {
Timepoint2Timespec(context->deadline(), &deadline);
}
@@ -117,14 +117,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
while (!context->IsCancelled()) {
gpr_sleep_until(gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_micros(request->param().client_cancel_after_us())));
+ gpr_time_from_micros(request->param().client_cancel_after_us(),
+ GPR_TIMESPAN)));
}
return Status::CANCELLED;
} else if (request->has_param() &&
request->param().server_cancel_after_us()) {
gpr_sleep_until(gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_micros(request->param().server_cancel_after_us())));
+ gpr_time_from_micros(request->param().server_cancel_after_us(),
+ GPR_TIMESPAN)));
return Status::CANCELLED;
} else {
EXPECT_FALSE(context->IsCancelled());
@@ -260,7 +262,7 @@ class End2endTest : public ::testing::Test {
TestServiceImpl service_;
TestServiceImpl special_service_;
TestServiceImplDupPkg dup_pkg_service_;
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
};
static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub,
@@ -375,7 +377,8 @@ TEST_F(End2endTest, EchoDeadlineForNoDeadlineRpc) {
Status s = stub_->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message());
EXPECT_TRUE(s.ok());
- EXPECT_EQ(response.param().request_deadline(), gpr_inf_future.tv_sec);
+ EXPECT_EQ(response.param().request_deadline(),
+ gpr_inf_future(GPR_CLOCK_REALTIME).tv_sec);
}
TEST_F(End2endTest, UnimplementedRpc) {
@@ -530,7 +533,7 @@ TEST_F(End2endTest, BadCredentials) {
void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_micros(delay_us)));
+ gpr_time_from_micros(delay_us, GPR_TIMESPAN)));
while (!service->signal_client()) {
}
context->TryCancel();
diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc
index 59a8edf509..74b40d54d8 100644
--- a/test/cpp/end2end/mock_test.cc
+++ b/test/cpp/end2end/mock_test.cc
@@ -37,12 +37,12 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -260,7 +260,7 @@ class MockTest : public ::testing::Test {
std::unique_ptr<Server> server_;
std::ostringstream server_address_;
TestServiceImpl service_;
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
};
// Do one real rpc and one mocked one
diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc
index 4d4d590bdd..5c7bb4e653 100644
--- a/test/cpp/end2end/server_crash_test.cc
+++ b/test/cpp/end2end/server_crash_test.cc
@@ -31,13 +31,10 @@
*
*/
-#include <thread>
-
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
@@ -84,8 +81,8 @@ class ServiceImpl GRPC_FINAL
gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
response.set_message(request.message());
stream->Write(response);
- gpr_sleep_until(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1)));
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(1, GPR_TIMESPAN)));
}
return Status::OK;
}
@@ -99,8 +96,8 @@ class ServiceImpl GRPC_FINAL
msg << "Hello " << i;
response.set_message(msg.str());
if (!writer->Write(response)) break;
- gpr_sleep_until(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(1)));
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(1, GPR_TIMESPAN)));
}
return Status::OK;
}
@@ -147,8 +144,8 @@ class CrashTest : public ::testing::Test {
TEST_F(CrashTest, ResponseStream) {
auto server = CreateServerAndClient("response");
- gpr_sleep_until(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5)));
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(5, GPR_TIMESPAN)));
KillClient();
server->Shutdown();
GPR_ASSERT(HadOneResponseStream());
@@ -157,8 +154,8 @@ TEST_F(CrashTest, ResponseStream) {
TEST_F(CrashTest, BidiStream) {
auto server = CreateServerAndClient("bidi");
- gpr_sleep_until(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5)));
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(5, GPR_TIMESPAN)));
KillClient();
server->Shutdown();
GPR_ASSERT(HadOneBidiStream());
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc
index 0b4d942566..e47139641b 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -38,12 +38,12 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/echo_duplicate.grpc.pb.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -71,7 +71,7 @@ namespace {
void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
EchoResponse* response) {
if (request->has_param() && request->param().echo_deadline()) {
- gpr_timespec deadline = gpr_inf_future;
+ gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
if (context->deadline() != system_clock::time_point::max()) {
Timepoint2Timespec(context->deadline(), &deadline);
}
@@ -97,14 +97,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
while (!context->IsCancelled()) {
gpr_sleep_until(gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_micros(request->param().client_cancel_after_us())));
+ gpr_time_from_micros(request->param().client_cancel_after_us(),
+ GPR_TIMESPAN)));
}
return Status::CANCELLED;
} else if (request->has_param() &&
request->param().server_cancel_after_us()) {
gpr_sleep_until(gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME),
- gpr_time_from_micros(request->param().server_cancel_after_us())));
+ gpr_time_from_micros(request->param().server_cancel_after_us(),
+ GPR_TIMESPAN)));
return Status::CANCELLED;
} else {
EXPECT_FALSE(context->IsCancelled());
@@ -206,7 +208,7 @@ class End2endTest : public ::testing::Test {
const int kMaxMessageSize_;
TestServiceImpl service_;
TestServiceImplDupPkg dup_pkg_service_;
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
};
static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub,
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index 65ce2e9c2a..96149c5e75 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -64,6 +64,7 @@ DEFINE_string(test_case, "large_unary",
"ping_pong : full-duplex streaming; "
"cancel_after_begin : cancel stream after starting it; "
"cancel_after_first_response: cancel on first response; "
+ "timeout_on_sleeping_server: deadline exceeds on stream; "
"service_account_creds : large_unary with service_account auth; "
"compute_engine_creds: large_unary with compute engine auth; "
"jwt_token_creds: large_unary with JWT token auth; "
@@ -101,6 +102,8 @@ int main(int argc, char** argv) {
client.DoCancelAfterBegin();
} else if (FLAGS_test_case == "cancel_after_first_response") {
client.DoCancelAfterFirstResponse();
+ } else if (FLAGS_test_case == "timeout_on_sleeping_server") {
+ client.DoTimeoutOnSleepingServer();
} else if (FLAGS_test_case == "service_account_creds") {
grpc::string json_key = GetServiceAccountJsonKey();
client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
@@ -119,6 +122,7 @@ int main(int argc, char** argv) {
client.DoPingPong();
client.DoCancelAfterBegin();
client.DoCancelAfterFirstResponse();
+ client.DoTimeoutOnSleepingServer();
// service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_enable_ssl) {
grpc::string json_key = GetServiceAccountJsonKey();
@@ -132,6 +136,7 @@ int main(int argc, char** argv) {
"Unsupported test case %s. Valid options are all|empty_unary|"
"large_unary|client_streaming|server_streaming|half_duplex|ping_pong|"
"cancel_after_begin|cancel_after_first_response|"
+ "timeout_on_sleeping_server|"
"service_account_creds|compute_engine_creds|jwt_token_creds",
FLAGS_test_case.c_str());
ret = 1;
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index f08f90b139..d88eff759c 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -351,5 +351,26 @@ void InteropClient::DoCancelAfterFirstResponse() {
gpr_log(GPR_INFO, "Canceling pingpong streaming done.");
}
+void InteropClient::DoTimeoutOnSleepingServer() {
+ gpr_log(GPR_INFO, "Sending Ping Pong streaming rpc with a short deadline...");
+ std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
+
+ ClientContext context;
+ std::chrono::system_clock::time_point deadline =
+ std::chrono::system_clock::now() + std::chrono::milliseconds(1);
+ context.set_deadline(deadline);
+ std::unique_ptr<ClientReaderWriter<StreamingOutputCallRequest,
+ StreamingOutputCallResponse>>
+ stream(stub->FullDuplexCall(&context));
+
+ StreamingOutputCallRequest request;
+ request.mutable_payload()->set_body(grpc::string(27182, '\0'));
+ stream->Write(request);
+
+ Status s = stream->Finish();
+ GPR_ASSERT(s.error_code() == StatusCode::DEADLINE_EXCEEDED);
+ gpr_log(GPR_INFO, "Pingpong streaming timeout done.");
+}
+
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h
index d9c895dfd9..d02e583d94 100644
--- a/test/cpp/interop/interop_client.h
+++ b/test/cpp/interop/interop_client.h
@@ -59,6 +59,7 @@ class InteropClient {
void DoResponseStreamingWithSlowConsumer();
void DoCancelAfterBegin();
void DoCancelAfterFirstResponse();
+ void DoTimeoutOnSleepingServer();
// Auth tests.
// username is a string containing the user email
void DoJwtTokenCreds(const grpc::string& username);
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 22b8910a24..db87872cf5 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -149,14 +149,12 @@ class TestServiceImpl : public TestService::Service {
StreamingOutputCallResponse response;
bool write_success = true;
while (write_success && stream->Read(&request)) {
- response.mutable_payload()->set_type(request.payload().type());
- if (request.response_parameters_size() == 0) {
- return Status(grpc::StatusCode::INTERNAL,
- "Request does not have response parameters.");
+ if (request.response_parameters_size() != 0) {
+ response.mutable_payload()->set_type(request.payload().type());
+ response.mutable_payload()->set_body(
+ grpc::string(request.response_parameters(0).size(), '\0'));
+ write_success = stream->Write(response);
}
- response.mutable_payload()->set_body(
- grpc::string(request.response_parameters(0).size(), '\0'));
- write_success = stream->Write(response);
}
if (write_success) {
return Status::OK;
diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc
index c2e750dcf7..30a78ffddf 100644
--- a/test/cpp/interop/server_helper.cc
+++ b/test/cpp/interop/server_helper.cc
@@ -58,5 +58,18 @@ std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() {
}
}
+InteropContextInspector::InteropContextInspector(
+ const ::grpc::ServerContext& context)
+ : context_(context) {}
+
+std::shared_ptr<const AuthContext> InteropContextInspector::GetAuthContext()
+ const {
+ return context_.auth_context();
+}
+
+bool InteropContextInspector::IsCancelled() const {
+ return context_.IsCancelled();
+}
+
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h
index f98e67bb67..ce977b4705 100644
--- a/test/cpp/interop/server_helper.h
+++ b/test/cpp/interop/server_helper.h
@@ -36,6 +36,7 @@
#include <memory>
+#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
namespace grpc {
@@ -43,6 +44,18 @@ namespace testing {
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials();
+class InteropContextInspector {
+ public:
+ InteropContextInspector(const ::grpc::ServerContext& context);
+
+ // Inspector methods, able to peek inside ServerContext, follow.
+ std::shared_ptr<const AuthContext> GetAuthContext() const;
+ bool IsCancelled() const;
+
+ private:
+ const ::grpc::ServerContext& context_;
+};
+
} // namespace testing
} // namespace grpc
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 5597bcd549..a0360295e0 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -186,7 +186,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Let everything warmup
gpr_log(GPR_INFO, "Warming up");
gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME);
- gpr_sleep_until(gpr_time_add(start, gpr_time_from_seconds(warmup_seconds)));
+ gpr_sleep_until(
+ gpr_time_add(start, gpr_time_from_seconds(warmup_seconds, GPR_TIMESPAN)));
// Start a run
gpr_log(GPR_INFO, "Starting");
@@ -211,8 +212,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Wait some time
gpr_log(GPR_INFO, "Running");
- gpr_sleep_until(
- gpr_time_add(start, gpr_time_from_seconds(benchmark_seconds)));
+ gpr_sleep_until(gpr_time_add(
+ start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN)));
// Finish a run
std::unique_ptr<ScenarioResult> result(new ScenarioResult);
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index f5251e961b..be23204608 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -45,6 +45,7 @@
#include <grpc/support/host_port.h>
#include <grpc++/async_unary_call.h>
#include <grpc++/config.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -52,7 +53,6 @@
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include <gtest/gtest.h>
-#include "src/cpp/server/thread_pool.h"
#include "test/cpp/qps/qpstest.grpc.pb.h"
#include "test/cpp/qps/server.h"
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index bc00de9ced..d90ff2212b 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -40,13 +40,13 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc++/config.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/server_credentials.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
-#include "src/cpp/server/thread_pool.h"
#include "test/cpp/qps/qpstest.grpc.pb.h"
#include "test/cpp/qps/server.h"
#include "test/cpp/qps/timer.h"
@@ -111,7 +111,7 @@ class SynchronousServer GRPC_FINAL : public grpc::testing::Server {
}
TestServiceImpl service_;
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
std::unique_ptr<grpc::Server> impl_;
};
diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc
index 2bc0a56970..7cf4903148 100644
--- a/test/cpp/qps/worker.cc
+++ b/test/cpp/qps/worker.cc
@@ -57,8 +57,8 @@ static void RunServer() {
QpsWorker worker(FLAGS_driver_port, FLAGS_server_port);
while (!got_sigint) {
- gpr_sleep_until(
- gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(5)));
+ gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_seconds(5, GPR_TIMESPAN)));
}
}
diff --git a/test/cpp/server/thread_pool_test.cc b/test/cpp/server/fixed_size_thread_pool_test.cc
index 824d785316..442e974fc1 100644
--- a/test/cpp/server/thread_pool_test.cc
+++ b/test/cpp/server/fixed_size_thread_pool_test.cc
@@ -35,17 +35,17 @@
#include <functional>
#include <mutex>
-#include "src/cpp/server/thread_pool.h"
+#include <grpc++/fixed_size_thread_pool.h>
#include <gtest/gtest.h>
namespace grpc {
-class ThreadPoolTest : public ::testing::Test {
+class FixedSizeThreadPoolTest : public ::testing::Test {
public:
- ThreadPoolTest() : thread_pool_(4) {}
+ FixedSizeThreadPoolTest() : thread_pool_(4) {}
protected:
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
};
void Callback(std::mutex* mu, std::condition_variable* cv, bool* done) {
@@ -54,12 +54,12 @@ void Callback(std::mutex* mu, std::condition_variable* cv, bool* done) {
cv->notify_all();
}
-TEST_F(ThreadPoolTest, ScheduleCallback) {
+TEST_F(FixedSizeThreadPoolTest, Add) {
std::mutex mu;
std::condition_variable cv;
bool done = false;
std::function<void()> callback = std::bind(Callback, &mu, &cv, &done);
- thread_pool_.ScheduleCallback(callback);
+ thread_pool_.Add(callback);
// Wait for the callback to finish.
std::unique_lock<std::mutex> lock(mu);
diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc
index 6cf86ea89b..00bb821ae6 100644
--- a/test/cpp/util/cli_call_test.cc
+++ b/test/cpp/util/cli_call_test.cc
@@ -34,12 +34,12 @@
#include "test/core/util/test_config.h"
#include "test/cpp/util/cli_call.h"
#include "test/cpp/util/echo.grpc.pb.h"
-#include "src/cpp/server/thread_pool.h"
#include <grpc++/channel_arguments.h>
#include <grpc++/channel_interface.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
#include <grpc++/credentials.h>
+#include <grpc++/fixed_size_thread_pool.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
@@ -102,7 +102,7 @@ class CliCallTest : public ::testing::Test {
std::unique_ptr<Server> server_;
std::ostringstream server_address_;
TestServiceImpl service_;
- ThreadPool thread_pool_;
+ FixedSizeThreadPool thread_pool_;
};
// Send a rpc with a normal stub and then a CliCall. Verify they match.
diff --git a/test/cpp/util/time_test.cc b/test/cpp/util/time_test.cc
index a3cfb1c961..4cb6ec4b4e 100644
--- a/test/cpp/util/time_test.cc
+++ b/test/cpp/util/time_test.cc
@@ -46,7 +46,8 @@ class TimeTest : public ::testing::Test {};
TEST_F(TimeTest, AbsolutePointTest) {
long us = 10000000L;
- gpr_timespec ts = gpr_time_from_micros(us);
+ gpr_timespec ts = gpr_time_from_micros(us, GPR_TIMESPAN);
+ ts.clock_type = GPR_CLOCK_REALTIME;
system_clock::time_point tp{microseconds(us)};
system_clock::time_point tp_converted = Timespec2Timepoint(ts);
gpr_timespec ts_converted;
@@ -61,15 +62,17 @@ TEST_F(TimeTest, AbsolutePointTest) {
// gpr_inf_future is treated specially and mapped to/from time_point::max()
TEST_F(TimeTest, InfFuture) {
EXPECT_EQ(system_clock::time_point::max(),
- Timespec2Timepoint(gpr_inf_future));
+ Timespec2Timepoint(gpr_inf_future(GPR_CLOCK_REALTIME)));
gpr_timespec from_time_point_max;
Timepoint2Timespec(system_clock::time_point::max(), &from_time_point_max);
- EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max));
+ EXPECT_EQ(
+ 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max));
// This will cause an overflow
Timepoint2Timespec(
std::chrono::time_point<system_clock, std::chrono::seconds>::max(),
&from_time_point_max);
- EXPECT_EQ(0, gpr_time_cmp(gpr_inf_future, from_time_point_max));
+ EXPECT_EQ(
+ 0, gpr_time_cmp(gpr_inf_future(GPR_CLOCK_REALTIME), from_time_point_max));
}
} // namespace