Merge pull request #11104 from yang-g/generic_deadline_propagation

Propagate deadline to GenericServerContext
pull/10897/head^2
Yang Gao 8 years ago committed by GitHub
commit 5854ac4af2
  1. 1
      src/cpp/server/server_cc.cc
  2. 21
      test/cpp/end2end/generic_end2end_test.cc

@ -686,6 +686,7 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag,
StringFromCopiedSlice(call_details_.method);
static_cast<GenericServerContext*>(context_)->host_ =
StringFromCopiedSlice(call_details_.host);
context_->deadline_ = call_details_.deadline;
}
grpc_slice_unref(call_details_.method);
grpc_slice_unref(call_details_.host);

@ -115,6 +115,10 @@ class GenericEnd2endTest : public ::testing::Test {
void client_fail(int i) { verify_ok(&cli_cq_, i, false); }
void SendRpc(int num_rpcs) {
SendRpc(num_rpcs, false, gpr_inf_future(GPR_CLOCK_MONOTONIC));
}
void SendRpc(int num_rpcs, bool check_deadline, gpr_timespec deadline) {
const grpc::string kMethodName("/grpc.cpp.test.util.EchoTestService/Echo");
for (int i = 0; i < num_rpcs; i++) {
EchoRequest send_request;
@ -129,6 +133,11 @@ class GenericEnd2endTest : public ::testing::Test {
// The string needs to be long enough to test heap-based slice.
send_request.set_message("Hello world. Hello world. Hello world.");
if (check_deadline) {
cli_ctx.set_deadline(deadline);
}
std::unique_ptr<GenericClientAsyncReaderWriter> call =
generic_stub_->Call(&cli_ctx, kMethodName, &cli_cq_, tag(1));
client_ok(1);
@ -147,6 +156,12 @@ class GenericEnd2endTest : public ::testing::Test {
verify_ok(srv_cq_.get(), 4, true);
EXPECT_EQ(server_host_, srv_ctx.host().substr(0, server_host_.length()));
EXPECT_EQ(kMethodName, srv_ctx.method());
if (check_deadline) {
EXPECT_TRUE(gpr_time_similar(deadline, srv_ctx.raw_deadline(),
gpr_time_from_millis(100, GPR_TIMESPAN)));
}
ByteBuffer recv_buffer;
stream.Read(&recv_buffer, tag(5));
server_ok(5);
@ -262,6 +277,12 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {
EXPECT_TRUE(recv_status.ok());
}
TEST_F(GenericEnd2endTest, Deadline) {
ResetStub();
SendRpc(1, true, gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_seconds(10, GPR_TIMESPAN)));
}
} // namespace
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save