Skip to content
Snippets Groups Projects
Commit bfc01822 authored by Vijay Pai's avatar Vijay Pai
Browse files

Merge pull request #1693 from dgquintas/fix_sleep_for

Replaced std::this_thread::sleep_for for gpr_sleep_until.
parents 2178c134 feb67f67
No related branches found
No related tags found
No related merge requests found
...@@ -96,14 +96,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { ...@@ -96,14 +96,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
signal_client_ = true; signal_client_ = true;
} }
while (!context->IsCancelled()) { while (!context->IsCancelled()) {
std::this_thread::sleep_for(std::chrono::microseconds( gpr_sleep_until(gpr_time_add(
request->param().client_cancel_after_us())); gpr_now(),
gpr_time_from_micros(request->param().client_cancel_after_us())));
} }
return Status::Cancelled; return Status::Cancelled;
} else if (request->has_param() && } else if (request->has_param() &&
request->param().server_cancel_after_us()) { request->param().server_cancel_after_us()) {
std::this_thread::sleep_for( gpr_sleep_until(gpr_time_add(
std::chrono::microseconds(request->param().server_cancel_after_us())); gpr_now(),
gpr_time_from_micros(request->param().server_cancel_after_us())));
return Status::Cancelled; return Status::Cancelled;
} else { } else {
EXPECT_FALSE(context->IsCancelled()); EXPECT_FALSE(context->IsCancelled());
...@@ -469,7 +471,7 @@ TEST_F(End2endTest, BadCredentials) { ...@@ -469,7 +471,7 @@ TEST_F(End2endTest, BadCredentials) {
} }
void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) {
std::this_thread::sleep_for(std::chrono::microseconds(delay_us)); gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_micros(delay_us)));
while (!service->signal_client()) { while (!service->signal_client()) {
} }
context->TryCancel(); context->TryCancel();
......
...@@ -94,14 +94,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { ...@@ -94,14 +94,16 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
signal_client_ = true; signal_client_ = true;
} }
while (!context->IsCancelled()) { while (!context->IsCancelled()) {
std::this_thread::sleep_for(std::chrono::microseconds( gpr_sleep_until(gpr_time_add(
request->param().client_cancel_after_us())); gpr_now(),
gpr_time_from_micros(request->param().client_cancel_after_us())));
} }
return Status::Cancelled; return Status::Cancelled;
} else if (request->has_param() && } else if (request->has_param() &&
request->param().server_cancel_after_us()) { request->param().server_cancel_after_us()) {
std::this_thread::sleep_for( gpr_sleep_until(gpr_time_add(
std::chrono::microseconds(request->param().server_cancel_after_us())); gpr_now(),
gpr_time_from_micros(request->param().server_cancel_after_us())));
return Status::Cancelled; return Status::Cancelled;
} else { } else {
EXPECT_FALSE(context->IsCancelled()); EXPECT_FALSE(context->IsCancelled());
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <thread> #include <thread>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/time.h>
#include <gflags/gflags.h> #include <gflags/gflags.h>
#include "qps_worker.h" #include "qps_worker.h"
...@@ -56,7 +57,7 @@ static void RunServer() { ...@@ -56,7 +57,7 @@ static void RunServer() {
QpsWorker worker(FLAGS_driver_port, FLAGS_server_port); QpsWorker worker(FLAGS_driver_port, FLAGS_server_port);
while (!got_sigint) { while (!got_sigint) {
std::this_thread::sleep_for(std::chrono::seconds(5)); gpr_sleep_until(gpr_time_add(gpr_now(), gpr_time_from_seconds(5)));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment