aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/end2end/thread_stress_test.cc6
-rw-r--r--test/cpp/interop/interop_client.cc29
-rw-r--r--test/cpp/interop/interop_server.cc5
-rw-r--r--test/cpp/qps/client_sync.cc4
-rw-r--r--test/cpp/qps/driver.cc3
-rw-r--r--test/cpp/qps/server_async.cc13
-rw-r--r--test/cpp/qps/server_sync.cc2
-rw-r--r--test/cpp/test/server_context_test_spouse_test.cc108
8 files changed, 159 insertions, 11 deletions
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc
index b021b34523..0b9d4cda9f 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -339,7 +339,11 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) {
ClientContext context;
Status s = stub->Echo(&context, request, &response);
EXPECT_EQ(response.message(), request.message());
- EXPECT_TRUE(s.ok());
+ if (!s.ok()) {
+ gpr_log(GPR_ERROR, "RPC error: %d: %s", s.error_code(),
+ s.error_message().c_str());
+ }
+ ASSERT_TRUE(s.ok());
}
}
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index ffd19eb1d5..f95d8c6ef6 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -827,21 +827,42 @@ bool InteropClient::DoStatusWithMessage() {
gpr_log(GPR_DEBUG,
"Sending RPC with a request for status code 2 and message");
+ const grpc::StatusCode test_code = grpc::StatusCode::UNKNOWN;
+ const grpc::string test_msg = "This is a test message";
+
+ // Test UnaryCall.
ClientContext context;
SimpleRequest request;
SimpleResponse response;
EchoStatus* requested_status = request.mutable_response_status();
- requested_status->set_code(grpc::StatusCode::UNKNOWN);
- grpc::string test_msg = "This is a test message";
+ requested_status->set_code(test_code);
requested_status->set_message(test_msg);
-
Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
-
if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) {
return false;
}
+ GPR_ASSERT(s.error_message() == test_msg);
+ // Test FullDuplexCall.
+ ClientContext stream_context;
+ std::shared_ptr<ClientReaderWriter<StreamingOutputCallRequest,
+ StreamingOutputCallResponse>>
+ stream(serviceStub_.Get()->FullDuplexCall(&stream_context));
+ StreamingOutputCallRequest streaming_request;
+ requested_status = streaming_request.mutable_response_status();
+ requested_status->set_code(test_code);
+ requested_status->set_message(test_msg);
+ stream->Write(streaming_request);
+ stream->WritesDone();
+ StreamingOutputCallResponse streaming_response;
+ while (stream->Read(&streaming_response))
+ ;
+ s = stream->Finish();
+ if (!AssertStatusCode(s, grpc::StatusCode::UNKNOWN)) {
+ return false;
+ }
GPR_ASSERT(s.error_message() == test_msg);
+
gpr_log(GPR_DEBUG, "Done testing Status and Message");
return true;
}
diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc
index 58f20aa611..8b50ae8c05 100644
--- a/test/cpp/interop/interop_server.cc
+++ b/test/cpp/interop/interop_server.cc
@@ -269,6 +269,11 @@ class TestServiceImpl : public TestService::Service {
StreamingOutputCallResponse response;
bool write_success = true;
while (write_success && stream->Read(&request)) {
+ if (request.has_response_status()) {
+ return Status(
+ static_cast<grpc::StatusCode>(request.response_status().code()),
+ request.response_status().message());
+ }
if (request.response_parameters_size() != 0) {
response.mutable_payload()->set_type(request.payload().type());
response.mutable_payload()->set_body(
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 8062424a1f..0ccf4e270b 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -130,6 +130,10 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
grpc::Status s =
stub->UnaryCall(&context, request_, &responses_[thread_idx]);
entry->set_value((UsageTimer::Now() - start) * 1e9);
+ if (!s.ok()) {
+ gpr_log(GPR_ERROR, "RPC error: %d: %s", s.error_code(),
+ s.error_message().c_str());
+ }
return s.ok();
}
};
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 7460bb526a..6c675e3483 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -45,6 +45,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
+#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/env.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
#include "test/core/util/port.h"
@@ -438,6 +439,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
start,
gpr_time_from_seconds(warmup_seconds + benchmark_seconds, GPR_TIMESPAN)));
+ gpr_timer_set_enabled(0);
+
// Finish a run
std::unique_ptr<ScenarioResult> result(new ScenarioResult);
Histogram merged_latencies;
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index 082b4bc72f..2fcc64819b 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -57,7 +57,7 @@ namespace testing {
template <class RequestType, class ResponseType, class ServiceType,
class ServerContextType>
-class AsyncQpsServerTest : public Server {
+class AsyncQpsServerTest GRPC_FINAL : public grpc::testing::Server {
public:
AsyncQpsServerTest(
const ServerConfig &config,
@@ -131,9 +131,7 @@ class AsyncQpsServerTest : public Server {
std::lock_guard<std::mutex> lock((*ss)->mutex);
(*ss)->shutdown = true;
}
- // TODO (vpai): Remove this deadline and allow Shutdown to finish properly
- auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(3);
- server_->Shutdown(deadline);
+ std::thread shutdown_thread(&AsyncQpsServerTest::ShutdownThreadFunc, this);
for (auto cq = srv_cqs_.begin(); cq != srv_cqs_.end(); ++cq) {
(*cq)->Shutdown();
}
@@ -146,9 +144,16 @@ class AsyncQpsServerTest : public Server {
while ((*cq)->Next(&got_tag, &ok))
;
}
+ shutdown_thread.join();
}
private:
+ void ShutdownThreadFunc() {
+ // TODO (vpai): Remove this deadline and allow Shutdown to finish properly
+ auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(3);
+ server_->Shutdown(deadline);
+ }
+
void ThreadFunc(int thread_idx) {
// Wait until work is available or we are shutting down
bool ok;
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index c774985bfa..0caed0ab49 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -31,8 +31,6 @@
*
*/
-#include <thread>
-
#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
diff --git a/test/cpp/test/server_context_test_spouse_test.cc b/test/cpp/test/server_context_test_spouse_test.cc
new file mode 100644
index 0000000000..e0d6a2ff67
--- /dev/null
+++ b/test/cpp/test/server_context_test_spouse_test.cc
@@ -0,0 +1,108 @@
+/*
+ *
+ * Copyright 2016, 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++/test/server_context_test_spouse.h>
+
+#include <cstring>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace grpc {
+namespace testing {
+
+const char key1[] = "metadata-key1";
+const char key2[] = "metadata-key2";
+const char val1[] = "metadata-val1";
+const char val2[] = "metadata-val2";
+
+bool ClientMetadataContains(const ServerContext& context,
+ const grpc::string_ref& key,
+ const grpc::string_ref& value) {
+ const auto& client_metadata = context.client_metadata();
+ for (auto iter = client_metadata.begin(); iter != client_metadata.end();
+ ++iter) {
+ if (iter->first == key && iter->second == value) {
+ return true;
+ }
+ }
+ return false;
+}
+
+TEST(ServerContextTestSpouseTest, ClientMetadata) {
+ ServerContext context;
+ ServerContextTestSpouse spouse(&context);
+
+ spouse.AddClientMetadata(key1, val1);
+ ASSERT_TRUE(ClientMetadataContains(context, key1, val1));
+
+ spouse.AddClientMetadata(key2, val2);
+ ASSERT_TRUE(ClientMetadataContains(context, key1, val1));
+ ASSERT_TRUE(ClientMetadataContains(context, key2, val2));
+}
+
+TEST(ServerContextTestSpouseTest, InitialMetadata) {
+ ServerContext context;
+ ServerContextTestSpouse spouse(&context);
+ std::multimap<grpc::string, grpc::string> metadata;
+
+ context.AddInitialMetadata(key1, val1);
+ metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1));
+ ASSERT_EQ(metadata, spouse.GetInitialMetadata());
+
+ context.AddInitialMetadata(key2, val2);
+ metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2));
+ ASSERT_EQ(metadata, spouse.GetInitialMetadata());
+}
+
+TEST(ServerContextTestSpouseTest, TrailingMetadata) {
+ ServerContext context;
+ ServerContextTestSpouse spouse(&context);
+ std::multimap<grpc::string, grpc::string> metadata;
+
+ context.AddTrailingMetadata(key1, val1);
+ metadata.insert(std::pair<grpc::string, grpc::string>(key1, val1));
+ ASSERT_EQ(metadata, spouse.GetTrailingMetadata());
+
+ context.AddTrailingMetadata(key2, val2);
+ metadata.insert(std::pair<grpc::string, grpc::string>(key2, val2));
+ ASSERT_EQ(metadata, spouse.GetTrailingMetadata());
+}
+
+} // namespace
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}