diff options
author | Makarand Dharmapurikar <makarandd@google.com> | 2016-06-09 16:28:02 -0700 |
---|---|---|
committer | Makarand Dharmapurikar <makarandd@google.com> | 2016-06-09 16:28:02 -0700 |
commit | 509246f59bb82432caf2ce5f16cf6f96c6ff3899 (patch) | |
tree | 74e3521dfdca542672c56dc259a7bfd7927c4968 /test/cpp/interop/server_main.cc | |
parent | d2c0256540ae2fe850c773be4bbb5c8225927ba3 (diff) |
implement interval_us functionality
Implemented ability to sleep before sending response as intended
by the ResponseParameters proto.
Diffstat (limited to 'test/cpp/interop/server_main.cc')
-rw-r--r-- | test/cpp/interop/server_main.cc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/cpp/interop/server_main.cc b/test/cpp/interop/server_main.cc index bbedda14d2..062857f3d6 100644 --- a/test/cpp/interop/server_main.cc +++ b/test/cpp/interop/server_main.cc @@ -181,6 +181,14 @@ class TestServiceImpl : public TestService::Service { response.mutable_payload())) { return Status(grpc::StatusCode::INTERNAL, "Error creating payload."); } + int time_us; + if ((time_us = request->response_parameters(i).interval_us()) > 0) { + // Sleep before response if needed + gpr_timespec sleep_time = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(time_us, GPR_TIMESPAN)); + gpr_sleep_until(sleep_time); + } write_success = writer->Write(response); } if (write_success) { @@ -218,6 +226,14 @@ class TestServiceImpl : public TestService::Service { response.mutable_payload()->set_type(request.payload().type()); response.mutable_payload()->set_body( grpc::string(request.response_parameters(0).size(), '\0')); + int time_us; + if ((time_us = request.response_parameters(0).interval_us()) > 0) { + // Sleep before response if needed + gpr_timespec sleep_time = + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_micros(time_us, GPR_TIMESPAN)); + gpr_sleep_until(sleep_time); + } write_success = stream->Write(response); } } |