diff options
author | Craig Tiller <ctiller@google.com> | 2015-09-30 09:44:28 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-09-30 09:44:28 -0700 |
commit | 072b93870eae270652fc83d88b60244c9bbc2f2c (patch) | |
tree | 4617ff7caa5849777f30aaf5b1ca5293553a8c2e /test | |
parent | eff4419b2a33777072cd7846650f552cb7c5e509 (diff) | |
parent | 74abf42096ea961520fdc6cc465997ab909b9586 (diff) |
Merge github.com:grpc/grpc into pfft
Diffstat (limited to 'test')
-rw-r--r-- | test/core/iomgr/udp_server_test.c | 4 | ||||
-rw-r--r-- | test/cpp/end2end/streaming_throughput_test.cc | 32 |
2 files changed, 24 insertions, 12 deletions
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 6d3dfeeb57..fc0026da4d 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -49,12 +49,12 @@ static grpc_pollset g_pollset; static int g_number_of_reads = 0; static int g_number_of_bytes_read = 0; -static void on_read(int fd, grpc_server *server) { +static void on_read(grpc_fd *emfd, grpc_server *server) { char read_buffer[512]; ssize_t byte_count; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); - byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); + byte_count = recv(emfd->fd, read_buffer, sizeof(read_buffer), 0); g_number_of_reads++; g_number_of_bytes_read += (int)byte_count; diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc index d64d96fe93..344bf507ce 100644 --- a/test/cpp/end2end/streaming_throughput_test.cc +++ b/test/cpp/end2end/streaming_throughput_test.cc @@ -31,9 +31,9 @@ * */ -#include <atomic> #include <mutex> #include <thread> +#include <time.h> #include <grpc++/channel.h> #include <grpc++/client_context.h> @@ -44,6 +44,7 @@ #include <grpc++/server_builder.h> #include <grpc++/server_context.h> #include <grpc/grpc.h> +#include <grpc/support/atm.h> #include <grpc/support/thd.h> #include <grpc/support/time.h> #include <gtest/gtest.h> @@ -99,12 +100,17 @@ namespace testing { class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { public: - static void BidiStream_Sender(ServerReaderWriter<EchoResponse, EchoRequest>* stream, std::atomic<bool>* should_exit) { + static void BidiStream_Sender(ServerReaderWriter<EchoResponse, EchoRequest>* stream, gpr_atm* should_exit) { EchoResponse response; response.set_message(kLargeString); - while (!should_exit->load()) { - // TODO(vpai): Decide if the below requires blocking annotation - std::this_thread::sleep_for(std::chrono::milliseconds(1)); + while (gpr_atm_acq_load(should_exit) == static_cast<gpr_atm>(0)) { + struct timespec tv = {0, 1000000}; // 1 ms + struct timespec rem; + // TODO (vpai): Mark this blocking + while (nanosleep(&tv, &rem) != 0) { + tv = rem; + }; + stream->Write(response); } } @@ -114,14 +120,20 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { ServerReaderWriter<EchoResponse, EchoRequest>* stream) GRPC_OVERRIDE { EchoRequest request; - std::atomic<bool> should_exit(false); + gpr_atm should_exit; + gpr_atm_rel_store(&should_exit, static_cast<gpr_atm>(0)); + std::thread sender(std::bind(&TestServiceImpl::BidiStream_Sender, stream, &should_exit)); while (stream->Read(&request)) { - // TODO(vpai): Decide if the below requires blocking annotation - std::this_thread::sleep_for(std::chrono::milliseconds(3)); + struct timespec tv = {0, 3000000}; // 3 ms + struct timespec rem; + // TODO (vpai): Mark this blocking + while (nanosleep(&tv, &rem) != 0) { + tv = rem; + }; } - should_exit.store(true); + gpr_atm_rel_store(&should_exit, static_cast<gpr_atm>(1)); sender.join(); return Status::OK; } @@ -145,7 +157,7 @@ class End2endTest : public ::testing::Test { void ResetStub() { std::shared_ptr<Channel> channel = CreateChannel( server_address_.str(), InsecureCredentials()); - stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel)); + stub_ = grpc::cpp::test::util::TestService::NewStub(channel); } std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_; |