aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2018-10-27 00:22:22 -0700
committerGravatar Yash Tibrewal <yashkt@google.com>2018-10-27 00:22:22 -0700
commitd075719477910931a31533c14177841943ff8f39 (patch)
treec10a1ec4417193610b6a8269767eba557b24cb74 /test
parent2475744c75d490a28dd3461d9ca8322f70c8e5aa (diff)
Add dummy interceptors to end2end_test and async_end2end_test
Diffstat (limited to 'test')
-rw-r--r--test/cpp/end2end/async_end2end_test.cc63
-rw-r--r--test/cpp/end2end/end2end_test.cc65
2 files changed, 122 insertions, 6 deletions
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 6ecb957801..8f9d903227 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -246,6 +246,53 @@ void TestScenario::Log() const {
class HealthCheck : public health::v1::Health::Service {};
+/* This interceptor does nothing. Just keeps a global count on the number of
+ * times it was invoked. */
+class DummyInterceptor : public experimental::Interceptor {
+ public:
+ DummyInterceptor(experimental::ClientRpcInfo* info) {}
+
+ virtual void Intercept(experimental::InterceptorBatchMethods* methods) {
+ if (methods->QueryInterceptionHookPoint(
+ experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA)) {
+ num_times_run_++;
+ } else if (methods->QueryInterceptionHookPoint(
+ experimental::InterceptionHookPoints::
+ POST_RECV_INITIAL_METADATA)) {
+ num_times_run_reverse_++;
+ }
+ methods->Proceed();
+ }
+
+ static void Reset() {
+ num_times_run_.store(0);
+ num_times_run_reverse_.store(0);
+ }
+
+ static int GetNumTimesRun() {
+ EXPECT_EQ(num_times_run_.load(), num_times_run_reverse_.load());
+ return num_times_run_.load();
+ }
+
+ static const int kNumInterceptorsRegistered = 5;
+
+ private:
+ static std::atomic<int> num_times_run_;
+ static std::atomic<int> num_times_run_reverse_;
+};
+
+std::atomic<int> DummyInterceptor::num_times_run_;
+std::atomic<int> DummyInterceptor::num_times_run_reverse_;
+
+class DummyInterceptorFactory
+ : public experimental::ClientInterceptorFactoryInterface {
+ public:
+ virtual experimental::Interceptor* CreateClientInterceptor(
+ experimental::ClientRpcInfo* info) override {
+ return new DummyInterceptor(info);
+ }
+};
+
class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
protected:
AsyncEnd2endTest() { GetParam().Log(); }
@@ -293,10 +340,22 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
ChannelArguments args;
auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
GetParam().credentials_type, &args);
+ auto creators = std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>(
+ new std::vector<std::unique_ptr<
+ experimental::ClientInterceptorFactoryInterface>>());
+ // Add dummy interceptors
+ for (auto i = 0; i < DummyInterceptor::kNumInterceptorsRegistered; i++) {
+ creators->push_back(std::unique_ptr<DummyInterceptorFactory>(
+ new DummyInterceptorFactory()));
+ }
std::shared_ptr<Channel> channel =
!(GetParam().inproc)
- ? CreateCustomChannel(server_address_.str(), channel_creds, args)
- : server_->InProcessChannel(args);
+ ? CreateCustomChannelWithInterceptors(server_address_.str(),
+ channel_creds, args,
+ std::move(creators))
+ : server_->experimental().InProcessChannelWithInterceptors(
+ args, std::move(creators));
stub_ = grpc::testing::EchoTestService::NewStub(channel);
}
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index fc07681535..becf78d870 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -179,7 +179,7 @@ class Proxy : public ::grpc::testing::EchoTestService::Service {
}
private:
- std::unique_ptr< ::grpc::testing::EchoTestService::Stub> stub_;
+ std::unique_ptr<::grpc::testing::EchoTestService::Stub> stub_;
};
class TestServiceImplDupPkg
@@ -216,6 +216,53 @@ void TestScenario::Log() const {
gpr_log(GPR_DEBUG, "%s", out.str().c_str());
}
+/* This interceptor does nothing. Just keeps a global count on the number of
+ * times it was invoked. */
+class DummyInterceptor : public experimental::Interceptor {
+ public:
+ DummyInterceptor(experimental::ClientRpcInfo* info) {}
+
+ virtual void Intercept(experimental::InterceptorBatchMethods* methods) {
+ if (methods->QueryInterceptionHookPoint(
+ experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA)) {
+ num_times_run_++;
+ } else if (methods->QueryInterceptionHookPoint(
+ experimental::InterceptionHookPoints::
+ POST_RECV_INITIAL_METADATA)) {
+ num_times_run_reverse_++;
+ }
+ methods->Proceed();
+ }
+
+ static void Reset() {
+ num_times_run_.store(0);
+ num_times_run_reverse_.store(0);
+ }
+
+ static int GetNumTimesRun() {
+ EXPECT_EQ(num_times_run_.load(), num_times_run_reverse_.load());
+ return num_times_run_.load();
+ }
+
+ static const int kNumInterceptorsRegistered = 5;
+
+ private:
+ static std::atomic<int> num_times_run_;
+ static std::atomic<int> num_times_run_reverse_;
+};
+
+std::atomic<int> DummyInterceptor::num_times_run_;
+std::atomic<int> DummyInterceptor::num_times_run_reverse_;
+
+class DummyInterceptorFactory
+ : public experimental::ClientInterceptorFactoryInterface {
+ public:
+ virtual experimental::Interceptor* CreateClientInterceptor(
+ experimental::ClientRpcInfo* info) override {
+ return new DummyInterceptor(info);
+ }
+};
+
class End2endTest : public ::testing::TestWithParam<TestScenario> {
protected:
End2endTest()
@@ -291,11 +338,21 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
}
args.SetString(GRPC_ARG_SECONDARY_USER_AGENT_STRING, "end2end_test");
+ auto creators = std::unique_ptr<std::vector<
+ std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>>(
+ new std::vector<std::unique_ptr<
+ experimental::ClientInterceptorFactoryInterface>>());
+ // Add dummy interceptors
+ for (auto i = 0; i < DummyInterceptor::kNumInterceptorsRegistered; i++) {
+ creators->push_back(std::unique_ptr<DummyInterceptorFactory>(
+ new DummyInterceptorFactory()));
+ }
if (!GetParam().inproc) {
- channel_ =
- CreateCustomChannel(server_address_.str(), channel_creds, args);
+ channel_ = CreateCustomChannelWithInterceptors(
+ server_address_.str(), channel_creds, args, std::move(creators));
} else {
- channel_ = server_->InProcessChannel(args);
+ channel_ = server_->experimental().InProcessChannelWithInterceptors(
+ args, std::move(creators));
}
}