Modify the test to have large number of threads receiving the RPCs and a

smaller number of threads sending the RPCs. This increases the
likelyhood of race-conditions on receiving threads.
pull/5126/head
Sree Kuchibhotla 9 years ago
parent 469e2fd3fb
commit 001db590ff
  1. 18
      test/cpp/end2end/thread_stress_test.cc

@ -55,7 +55,9 @@ using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
using std::chrono::system_clock;
const int kNumThreads = 100; // Number of threads
const int kNumThreads = 100; // Number of threads
const int kNumAsyncSendThreads = 2;
const int kNumAsyncReceiveThreads = 50;
const int kNumRpcs = 1000; // Number of RPCs per thread
namespace grpc {
@ -273,7 +275,7 @@ class AsyncClientEnd2endTest : public ::testing::Test {
for (int i = 0; i < num_rpcs; ++i) {
AsyncClientCall* call = new AsyncClientCall;
EchoRequest request;
request.set_message("Hello");
request.set_message("Hello: " + std::to_string(i));
call->response_reader =
common_.GetStub()->AsyncEcho(&call->context, request, &cq_);
call->response_reader->Finish(&call->response, &call->status,
@ -290,7 +292,9 @@ class AsyncClientEnd2endTest : public ::testing::Test {
bool ok = false;
if (!cq_.Next(&got_tag, &ok)) break;
AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag);
GPR_ASSERT(ok);
if (!ok) {
gpr_log(GPR_DEBUG, "Error: %d", call->status.error_code());
}
delete call;
bool notify;
@ -315,22 +319,22 @@ class AsyncClientEnd2endTest : public ::testing::Test {
TEST_F(AsyncClientEnd2endTest, ThreadStress) {
common_.ResetStub();
std::vector<std::thread*> send_threads, completion_threads;
for (int i = 0; i < kNumThreads / 2; ++i) {
for (int i = 0; i < kNumAsyncReceiveThreads; ++i) {
completion_threads.push_back(new std::thread(
&AsyncClientEnd2endTest_ThreadStress_Test::AsyncCompleteRpc, this));
}
for (int i = 0; i < kNumThreads / 2; ++i) {
for (int i = 0; i < kNumAsyncSendThreads; ++i) {
send_threads.push_back(
new std::thread(&AsyncClientEnd2endTest_ThreadStress_Test::AsyncSendRpc,
this, kNumRpcs));
}
for (int i = 0; i < kNumThreads / 2; ++i) {
for (int i = 0; i < kNumAsyncSendThreads; ++i) {
send_threads[i]->join();
delete send_threads[i];
}
Wait();
for (int i = 0; i < kNumThreads / 2; ++i) {
for (int i = 0; i < kNumAsyncReceiveThreads; ++i) {
completion_threads[i]->join();
delete completion_threads[i];
}

Loading…
Cancel
Save