Skip to content
Snippets Groups Projects
Commit 98f2f754 authored by Vijay Pai's avatar Vijay Pai
Browse files

Used TYPED_TEST to parametrize

Include all 4 sync/async client/server combos
parent 40d1a2cb
No related branches found
No related tags found
No related merge requests found
...@@ -318,6 +318,7 @@ class CommonStressTestAsyncServer ...@@ -318,6 +318,7 @@ class CommonStressTestAsyncServer
std::vector<std::thread*> server_threads_; std::vector<std::thread*> server_threads_;
}; };
template <class Common>
class End2endTest : public ::testing::Test { class End2endTest : public ::testing::Test {
protected: protected:
End2endTest() {} End2endTest() {}
...@@ -325,17 +326,7 @@ class End2endTest : public ::testing::Test { ...@@ -325,17 +326,7 @@ class End2endTest : public ::testing::Test {
void TearDown() GRPC_OVERRIDE { common_.TearDown(); } void TearDown() GRPC_OVERRIDE { common_.TearDown(); }
void ResetStub() { common_.ResetStub(); } void ResetStub() { common_.ResetStub(); }
CommonStressTestSyncServer common_; Common 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_;
}; };
static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) { 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) { ...@@ -351,23 +342,16 @@ static void SendRpc(grpc::testing::EchoTestService::Stub* stub, int num_rpcs) {
} }
} }
TEST_F(End2endTest, ThreadStress) { typedef ::testing::Types<CommonStressTestSyncServer,
common_.ResetStub(); CommonStressTestAsyncServer>
std::vector<std::thread*> threads; CommonTypes;
for (int i = 0; i < kNumThreads; ++i) { TYPED_TEST_CASE(End2endTest, CommonTypes);
threads.push_back(new std::thread(SendRpc, common_.GetStub(), kNumRpcs)); TYPED_TEST(End2endTest, ThreadStress) {
} this->common_.ResetStub();
for (int i = 0; i < kNumThreads; ++i) {
threads[i]->join();
delete threads[i];
}
}
TEST_F(End2endTestAsyncServer, ThreadStress) {
common_.ResetStub();
std::vector<std::thread*> threads; std::vector<std::thread*> threads;
for (int i = 0; i < kNumThreads; ++i) { 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) { for (int i = 0; i < kNumThreads; ++i) {
threads[i]->join(); threads[i]->join();
...@@ -375,6 +359,7 @@ TEST_F(End2endTestAsyncServer, ThreadStress) { ...@@ -375,6 +359,7 @@ TEST_F(End2endTestAsyncServer, ThreadStress) {
} }
} }
template <class Common>
class AsyncClientEnd2endTest : public ::testing::Test { class AsyncClientEnd2endTest : public ::testing::Test {
protected: protected:
AsyncClientEnd2endTest() : rpcs_outstanding_(0) {} AsyncClientEnd2endTest() : rpcs_outstanding_(0) {}
...@@ -442,31 +427,33 @@ class AsyncClientEnd2endTest : public ::testing::Test { ...@@ -442,31 +427,33 @@ class AsyncClientEnd2endTest : public ::testing::Test {
} }
} }
CommonStressTestSyncServer common_; Common common_;
CompletionQueue cq_; CompletionQueue cq_;
mutex mu_; mutex mu_;
condition_variable cv_; condition_variable cv_;
int rpcs_outstanding_; int rpcs_outstanding_;
}; };
TEST_F(AsyncClientEnd2endTest, ThreadStress) { TYPED_TEST_CASE(AsyncClientEnd2endTest, CommonTypes);
common_.ResetStub(); TYPED_TEST(AsyncClientEnd2endTest, ThreadStress) {
this->common_.ResetStub();
std::vector<std::thread *> send_threads, completion_threads; std::vector<std::thread *> send_threads, completion_threads;
for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { for (int i = 0; i < kNumAsyncReceiveThreads; ++i) {
completion_threads.push_back(new std::thread( 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) { for (int i = 0; i < kNumAsyncSendThreads; ++i) {
send_threads.push_back( send_threads.push_back(new std::thread(
new std::thread(&AsyncClientEnd2endTest_ThreadStress_Test::AsyncSendRpc, &AsyncClientEnd2endTest_ThreadStress_Test<TypeParam>::AsyncSendRpc,
this, kNumRpcs)); this, kNumRpcs));
} }
for (int i = 0; i < kNumAsyncSendThreads; ++i) { for (int i = 0; i < kNumAsyncSendThreads; ++i) {
send_threads[i]->join(); send_threads[i]->join();
delete send_threads[i]; delete send_threads[i];
} }
Wait(); this->Wait();
for (int i = 0; i < kNumAsyncReceiveThreads; ++i) { for (int i = 0; i < kNumAsyncReceiveThreads; ++i) {
completion_threads[i]->join(); completion_threads[i]->join();
delete completion_threads[i]; delete completion_threads[i];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment