diff options
author | 2017-05-04 10:02:24 -0700 | |
---|---|---|
committer | 2017-07-14 16:23:54 -0700 | |
commit | 3d7d5f4ed222b687ecbd03c172e1042b7d460304 (patch) | |
tree | a47a74501f11b78fd9642a6d507813a43b7d9ddb /test/cpp/end2end/thread_stress_test.cc | |
parent | abcdfc9676c46a7f04091cf0e7f84f0e2b3fcf86 (diff) |
Create inproc transport, add relevant tests, exclude irrelevant tests
Diffstat (limited to 'test/cpp/end2end/thread_stress_test.cc')
-rw-r--r-- | test/cpp/end2end/thread_stress_test.cc | 102 |
1 files changed, 63 insertions, 39 deletions
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 542df00fb4..f990a7ed9d 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -151,16 +151,6 @@ class TestServiceImpl : public ::grpc::testing::EchoTestService::Service { std::mutex mu_; }; -class TestServiceImplDupPkg - : public ::grpc::testing::duplicate::EchoTestService::Service { - public: - Status Echo(ServerContext* context, const EchoRequest* request, - EchoResponse* response) override { - response->set_message("no package"); - return Status::OK; - } -}; - template <class Service> class CommonStressTest { public: @@ -168,63 +158,92 @@ class CommonStressTest { virtual ~CommonStressTest() {} virtual void SetUp() = 0; virtual void TearDown() = 0; - void ResetStub() { - std::shared_ptr<Channel> channel = - CreateChannel(server_address_.str(), InsecureChannelCredentials()); - stub_ = grpc::testing::EchoTestService::NewStub(channel); - } + virtual void ResetStub() = 0; grpc::testing::EchoTestService::Stub* GetStub() { return stub_.get(); } protected: - void SetUpStart(ServerBuilder* builder, Service* service) { - int port = grpc_pick_unused_port_or_die(); - server_address_ << "localhost:" << port; - // Setup server - builder->AddListeningPort(server_address_.str(), - InsecureServerCredentials()); + std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; + std::unique_ptr<Server> server_; + + virtual void SetUpStart(ServerBuilder* builder, Service* service) = 0; + void SetUpStartCommon(ServerBuilder* builder, Service* service) { builder->RegisterService(service); builder->SetMaxMessageSize( kMaxMessageSize_); // For testing max message size. - builder->RegisterService(&dup_pkg_service_); } void SetUpEnd(ServerBuilder* builder) { server_ = builder->BuildAndStart(); } void TearDownStart() { server_->Shutdown(); } void TearDownEnd() {} private: - std::unique_ptr<grpc::testing::EchoTestService::Stub> stub_; - std::unique_ptr<Server> server_; - std::ostringstream server_address_; const int kMaxMessageSize_; - TestServiceImplDupPkg dup_pkg_service_; }; -class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> { +template <class Service> +class CommonStressTestInsecure : public CommonStressTest<Service> { + public: + void ResetStub() override { + std::shared_ptr<Channel> channel = + CreateChannel(server_address_.str(), InsecureChannelCredentials()); + this->stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + protected: + void SetUpStart(ServerBuilder* builder, Service* service) override { + int port = grpc_pick_unused_port_or_die(); + this->server_address_ << "localhost:" << port; + // Setup server + builder->AddListeningPort(server_address_.str(), + InsecureServerCredentials()); + this->SetUpStartCommon(builder, service); + } + + private: + std::ostringstream server_address_; +}; + +template <class Service> +class CommonStressTestInproc : public CommonStressTest<Service> { + public: + void ResetStub() override { + ChannelArguments args; + std::shared_ptr<Channel> channel = this->server_->InProcessChannel(args); + this->stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + protected: + void SetUpStart(ServerBuilder* builder, Service* service) override { + this->SetUpStartCommon(builder, service); + } +}; + +template <class BaseClass> +class CommonStressTestSyncServer : public BaseClass { public: void SetUp() override { ServerBuilder builder; - SetUpStart(&builder, &service_); - SetUpEnd(&builder); + this->SetUpStart(&builder, &service_); + this->SetUpEnd(&builder); } void TearDown() override { - TearDownStart(); - TearDownEnd(); + this->TearDownStart(); + this->TearDownEnd(); } private: TestServiceImpl service_; }; -class CommonStressTestAsyncServer - : public CommonStressTest<grpc::testing::EchoTestService::AsyncService> { +template <class BaseClass> +class CommonStressTestAsyncServer : public BaseClass { public: CommonStressTestAsyncServer() : contexts_(kNumAsyncServerThreads * 100) {} void SetUp() override { shutting_down_ = false; ServerBuilder builder; - SetUpStart(&builder, &service_); + this->SetUpStart(&builder, &service_); cq_ = builder.AddCompletionQueue(); - SetUpEnd(&builder); + this->SetUpEnd(&builder); for (int i = 0; i < kNumAsyncServerThreads * 100; i++) { RefreshContext(i); } @@ -236,7 +255,7 @@ class CommonStressTestAsyncServer void TearDown() override { { std::unique_lock<std::mutex> l(mu_); - TearDownStart(); + this->TearDownStart(); shutting_down_ = true; cq_->Shutdown(); } @@ -249,7 +268,7 @@ class CommonStressTestAsyncServer bool ignored_ok; while (cq_->Next(&ignored_tag, &ignored_ok)) ; - TearDownEnd(); + this->TearDownEnd(); } private: @@ -332,8 +351,13 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { } } -typedef ::testing::Types<CommonStressTestSyncServer, - CommonStressTestAsyncServer> +typedef ::testing::Types< + CommonStressTestSyncServer<CommonStressTestInsecure<TestServiceImpl>>, + CommonStressTestSyncServer<CommonStressTestInproc<TestServiceImpl>>, + CommonStressTestAsyncServer< + CommonStressTestInsecure<grpc::testing::EchoTestService::AsyncService>>, + CommonStressTestAsyncServer< + CommonStressTestInproc<grpc::testing::EchoTestService::AsyncService>>> CommonTypes; TYPED_TEST_CASE(End2endTest, CommonTypes); TYPED_TEST(End2endTest, ThreadStress) { |