Make sure that some ops don't start concurrently with Finish

pull/23416/head
Vijay Pai 4 years ago
parent 598e171746
commit 0ab6db4fe8
  1. 27
      test/cpp/end2end/test_service_impl.cc

@ -502,12 +502,20 @@ CallbackTestServiceImpl::ResponseStream(
if (num_msgs_sent_ == server_responses_to_send_ - 1 && if (num_msgs_sent_ == server_responses_to_send_ - 1 &&
server_coalescing_api_ != 0) { server_coalescing_api_ != 0) {
num_msgs_sent_++; num_msgs_sent_++;
StartWriteLast(&response_, WriteOptions()); {
std::lock_guard<std::mutex> l(finish_mu_);
if (!finished_) {
StartWriteLast(&response_, WriteOptions());
}
}
// If we use WriteLast, we shouldn't wait before attempting Finish // If we use WriteLast, we shouldn't wait before attempting Finish
FinishOnce(Status::OK); FinishOnce(Status::OK);
} else { } else {
num_msgs_sent_++; num_msgs_sent_++;
StartWrite(&response_); std::lock_guard<std::mutex> l(finish_mu_);
if (!finished_) {
StartWrite(&response_);
}
} }
} }
experimental::CallbackServerContext* const ctx_; experimental::CallbackServerContext* const ctx_;
@ -571,12 +579,15 @@ CallbackTestServiceImpl::BidiStream(
if (ok) { if (ok) {
num_msgs_read_++; num_msgs_read_++;
response_.set_message(request_.message()); response_.set_message(request_.message());
if (num_msgs_read_ == server_write_last_) { std::lock_guard<std::mutex> l(finish_mu_);
StartWriteLast(&response_, WriteOptions()); if (!finished_) {
// If we use WriteLast, we shouldn't wait before attempting Finish if (num_msgs_read_ == server_write_last_) {
} else { StartWriteLast(&response_, WriteOptions());
StartWrite(&response_); // If we use WriteLast, we shouldn't wait before attempting Finish
return; } else {
StartWrite(&response_);
return;
}
} }
} }

Loading…
Cancel
Save