Add a test only method to reset global interceptor

pull/17978/head
Yash Tibrewal 6 years ago
parent c71b2f4fb7
commit cddb5519f2
  1. 5
      src/cpp/client/client_interceptor.cc
  2. 7
      test/cpp/end2end/client_interceptors_end2end_test.cc

@ -35,5 +35,10 @@ void RegisterGlobalClientInterceptorFactory(
}
internal::g_global_client_interceptor_factory = factory;
}
// For testing purposes only.
void TestOnlyResetGlobalClientInterceptorFactory() {
internal::g_global_client_interceptor_factory = nullptr;
}
} // namespace experimental
} // namespace grpc

@ -40,6 +40,10 @@
#include <gtest/gtest.h>
namespace grpc {
namespace experimental {
void TestOnlyResetGlobalClientInterceptorFactory();
}
namespace testing {
namespace {
@ -894,6 +898,7 @@ TEST_F(ClientGlobalInterceptorEnd2endTest, DummyGlobalInterceptor) {
MakeCall(channel);
// Make sure all 20 dummy interceptors were run with the global interceptor
EXPECT_EQ(DummyInterceptor::GetNumTimesRun(), 21);
experimental::TestOnlyResetGlobalClientInterceptorFactory();
}
TEST_F(ClientGlobalInterceptorEnd2endTest, LoggingGlobalInterceptor) {
@ -917,6 +922,7 @@ TEST_F(ClientGlobalInterceptorEnd2endTest, LoggingGlobalInterceptor) {
MakeCall(channel);
// Make sure all 20 dummy interceptors were run
EXPECT_EQ(DummyInterceptor::GetNumTimesRun(), 20);
experimental::TestOnlyResetGlobalClientInterceptorFactory();
}
TEST_F(ClientGlobalInterceptorEnd2endTest, HijackingGlobalInterceptor) {
@ -940,6 +946,7 @@ TEST_F(ClientGlobalInterceptorEnd2endTest, HijackingGlobalInterceptor) {
MakeCall(channel);
// Make sure all 20 dummy interceptors were run
EXPECT_EQ(DummyInterceptor::GetNumTimesRun(), 20);
experimental::TestOnlyResetGlobalClientInterceptorFactory();
}
} // namespace

Loading…
Cancel
Save