diff options
author | Vijay Pai <vpai@google.com> | 2016-03-29 00:54:11 -0700 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2016-03-29 00:54:11 -0700 |
commit | 98f2f754b8b4cf460720eaf605c55734f28b2057 (patch) | |
tree | 8b719b3382ec4e1a1d6cf47be93c9288b0514bd8 | |
parent | 40d1a2cb876e3ee19bccd5a59f3cfba48a22c4a5 (diff) |
Used TYPED_TEST to parametrize
Include all 4 sync/async client/server combos
-rw-r--r-- | test/cpp/end2end/thread_stress_test.cc | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 22ea3a82b4..3f75a0c92e 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -318,6 +318,7 @@ class CommonStressTestAsyncServer std::vector<std::thread*> server_threads_; }; +template <class Common> class End2endTest : public ::testing::Test { protected: End2endTest() {} @@ -325,17 +326,7 @@ class End2endTest : public ::testing::Test { void TearDown() GRPC_OVERRIDE { common_.TearDown(); } void ResetStub() { common_.ResetStub(); } - CommonStressTestSyncServer common_; -}; - -class End2endTestAsyncServer : public ::testing::Test { - protected: - End2endTestAsyncServer() {} - void SetUp() GRPC_OVERRIDE { common_.SetUp(); } - void TearDown() GRPC_OVERRIDE { common_.TearDown(); } - void ResetStub() { common_.ResetStub(); } - - CommonStressTestAsyncServer common_; + Common common_; }; static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { @@ -351,23 +342,16 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { } } -TEST_F(End2endTest, ThreadStress) { - common_.ResetStub(); - std::vector<std::thread*> threads; - for (int i = 0; i < kNumThreads; ++i) { - threads.push_back(new std::thread(SendRpc, common_.GetStub(), kNumRpcs)); - } - for (int i = 0; i < kNumThreads; ++i) { - threads[i]->join(); - delete threads[i]; - } -} - -TEST_F(End2endTestAsyncServer, ThreadStress) { - common_.ResetStub(); +typedef ::testing::Types<CommonStressTestSyncServer, + CommonStressTestAsyncServer> + CommonTypes; +TYPED_TEST_CASE(End2endTest, CommonTypes); +TYPED_TEST(End2endTest, ThreadStress) { + this->common_.ResetStub(); std::vector<std::thread*> threads; for (int i = 0; i < kNumThreads; ++i) { - threads.push_back(new std::thread(SendRpc, common_.GetStub(), kNumRpcs)); + threads.push_back( + new std::thread(SendRpc, this->common_.GetStub(), kNumRpcs)); } for (int i = 0; i < kNumThreads; ++i) { threads[i]->join(); @@ -375,6 +359,7 @@ TEST_F(End2endTestAsyncServer, ThreadStress) { } } +template <class Common> class AsyncClientEnd2endTest : public ::testing::Test { protected: AsyncClientEnd2endTest() : rpcs_outstanding_(0) {} @@ -442,31 +427,33 @@ class AsyncClientEnd2endTest : public ::testing::Test { } } - CommonStressTestSyncServer common_; + Common common_; CompletionQueue cq_; mutex mu_; condition_variable cv_; int rpcs_outstanding_; }; -TEST_F(AsyncClientEnd2endTest, ThreadStress) { - common_.ResetStub(); +TYPED_TEST_CASE(AsyncClientEnd2endTest, CommonTypes); +TYPED_TEST(AsyncClientEnd2endTest, ThreadStress) { + this->common_.ResetStub(); std::vector<std::thread *> send_threads, completion_threads; for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { completion_threads.push_back(new std::thread( - &AsyncClientEnd2endTest_ThreadStress_Test::AsyncCompleteRpc, this)); + &AsyncClientEnd2endTest_ThreadStress_Test<TypeParam>::AsyncCompleteRpc, + this)); } for (int i = 0; i < kNumAsyncSendThreads; ++i) { - send_threads.push_back( - new std::thread(&AsyncClientEnd2endTest_ThreadStress_Test::AsyncSendRpc, - this, kNumRpcs)); + send_threads.push_back(new std::thread( + &AsyncClientEnd2endTest_ThreadStress_Test<TypeParam>::AsyncSendRpc, + this, kNumRpcs)); } for (int i = 0; i < kNumAsyncSendThreads; ++i) { send_threads[i]->join(); delete send_threads[i]; } - Wait(); + this->Wait(); for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { completion_threads[i]->join(); delete completion_threads[i]; |