From 509246f59bb82432caf2ce5f16cf6f96c6ff3899 Mon Sep 17 00:00:00 2001
From: Makarand Dharmapurikar <makarandd@google.com>
Date: Thu, 9 Jun 2016 16:28:02 -0700
Subject: [PATCH] implement interval_us functionality

Implemented ability to sleep before sending response as intended
by the ResponseParameters proto.
---
 test/cpp/interop/server_main.cc | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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);
       }
     }
-- 
GitLab