aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/end2end
diff options
context:
space:
mode:
authorGravatar Hope Casey-Allen <hcaseyal@google.com>2018-11-29 15:57:53 -0800
committerGravatar Hope Casey-Allen <hcaseyal@google.com>2018-11-29 15:57:53 -0800
commit470ea1784329ec5637b41455a8dbd2ea2b811b58 (patch)
tree072ecdd59f10ca804a1a2735a9881796e3c5ebb1 /test/cpp/end2end
parent1b9df7d183f3a4f7d2bf02bb1ed8fae8ebe70c86 (diff)
Debugging unimplemented error in CheckClientInitialMetadata
Diffstat (limited to 'test/cpp/end2end')
-rw-r--r--test/cpp/end2end/BUILD1
-rw-r--r--test/cpp/end2end/client_callback_end2end_test.cc34
-rw-r--r--test/cpp/end2end/test_service_impl.cc29
-rw-r--r--test/cpp/end2end/test_service_impl.h7
4 files changed, 71 insertions, 0 deletions
diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD
index 4e3d841db0..446804401a 100644
--- a/test/cpp/end2end/BUILD
+++ b/test/cpp/end2end/BUILD
@@ -124,6 +124,7 @@ grpc_cc_test(
"//:grpc",
"//:grpc++",
"//src/proto/grpc/testing:echo_messages_proto",
+ "//src/proto/grpc/testing:simple_messages_proto",
"//src/proto/grpc/testing:echo_proto",
"//test/core/util:gpr_test_util",
"//test/core/util:grpc_test_util",
diff --git a/test/cpp/end2end/client_callback_end2end_test.cc b/test/cpp/end2end/client_callback_end2end_test.cc
index a35991396a..e25a6689e5 100644
--- a/test/cpp/end2end/client_callback_end2end_test.cc
+++ b/test/cpp/end2end/client_callback_end2end_test.cc
@@ -201,6 +201,40 @@ TEST_P(ClientCallbackEnd2endTest, SequentialRpcs) {
SendRpcs(10, false);
}
+TEST_P(ClientCallbackEnd2endTest, SendClientInitialMetadata) {
+ ResetStub();
+ SimpleRequest request;
+ SimpleResponse response;
+ ClientContext cli_ctx;
+
+ cli_ctx.AddMetadata(kCheckClientInitialMetadataKey,
+ kCheckClientInitialMetadataVal);
+
+ std::mutex mu;
+ std::condition_variable cv;
+ bool done = false;
+ stub_->experimental_async()->CheckClientInitialMetadata(
+ &cli_ctx, &request, &response, [&done, &mu, &cv](Status s) {
+ std::cout << s.error_code() << std::endl;
+ gpr_log(GPR_ERROR, s.error_message().c_str());
+ gpr_log(GPR_ERROR, s.error_details().c_str());
+ GPR_ASSERT(s.ok());
+ std::lock_guard<std::mutex> l(mu);
+
+ done = true;
+ cv.notify_one();
+ });
+ std::unique_lock<std::mutex> l(mu);
+ while (!done) {
+ cv.wait(l);
+ }
+}
+
+TEST_P(ClientCallbackEnd2endTest, SimpleRpcWithBinaryMetadata) {
+ ResetStub();
+ SendRpcs(1, true);
+}
+
TEST_P(ClientCallbackEnd2endTest, SequentialRpcsWithVariedBinaryMetadataValue) {
ResetStub();
SendRpcs(10, true);
diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc
index 605356724f..a7be8a798a 100644
--- a/test/cpp/end2end/test_service_impl.cc
+++ b/test/cpp/end2end/test_service_impl.cc
@@ -69,6 +69,22 @@ void CheckServerAuthContext(
EXPECT_EQ(expected_client_identity, identity[0]);
}
}
+
+// Returns the number of pairs in metadata that exactly match the given
+// key-value pair. Returns -1 if the pair wasn't found.
+int MetadataMatchCount(
+ const std::multimap<grpc::string_ref, grpc::string_ref>& metadata,
+ const grpc::string& key, const grpc::string& value) {
+ int count = 0;
+ for (std::multimap<grpc::string_ref, grpc::string_ref>::const_iterator iter =
+ metadata.begin();
+ iter != metadata.end(); ++iter) {
+ if (ToString(iter->first) == key && ToString(iter->second) == value) {
+ count++;
+ }
+ }
+ return count;
+}
} // namespace
Status TestServiceImpl::Echo(ServerContext* context, const EchoRequest* request,
@@ -165,6 +181,19 @@ Status TestServiceImpl::Echo(ServerContext* context, const EchoRequest* request,
return Status::OK;
}
+void CallbackTestServiceImpl::CheckClientInitialMetadata(
+ ServerContext* context, const SimpleRequest* request,
+ SimpleResponse* response,
+ experimental::ServerCallbackRpcController* controller) {
+ EXPECT_EQ(MetadataMatchCount(context->client_metadata(),
+ kCheckClientInitialMetadataKey,
+ kCheckClientInitialMetadataVal),
+ 1);
+ EXPECT_EQ(1u,
+ context->client_metadata().count(kCheckClientInitialMetadataKey));
+ controller->Finish(Status::OK);
+}
+
void CallbackTestServiceImpl::Echo(
ServerContext* context, const EchoRequest* request, EchoResponse* response,
experimental::ServerCallbackRpcController* controller) {
diff --git a/test/cpp/end2end/test_service_impl.h b/test/cpp/end2end/test_service_impl.h
index ddfe94487e..124d5e512b 100644
--- a/test/cpp/end2end/test_service_impl.h
+++ b/test/cpp/end2end/test_service_impl.h
@@ -36,6 +36,8 @@ const char* const kServerTryCancelRequest = "server_try_cancel";
const char* const kDebugInfoTrailerKey = "debug-info-bin";
const char* const kServerFinishAfterNReads = "server_finish_after_n_reads";
const char* const kServerUseCoalescingApi = "server_use_coalescing_api";
+const char* const kCheckClientInitialMetadataKey = "custom_client_metadata";
+const char* const kCheckClientInitialMetadataVal = "Value for client metadata";
typedef enum {
DO_NOT_CANCEL = 0,
@@ -95,6 +97,11 @@ class CallbackTestServiceImpl
EchoResponse* response,
experimental::ServerCallbackRpcController* controller) override;
+ void CheckClientInitialMetadata(
+ ServerContext* context, const SimpleRequest* request,
+ SimpleResponse* response,
+ experimental::ServerCallbackRpcController* controller) override;
+
// Unimplemented is left unimplemented to test the returned error.
bool signal_client() {
std::unique_lock<std::mutex> lock(mu_);