aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2015-08-05 19:15:36 -0700
committerGravatar Vijay Pai <vpai@google.com>2015-08-05 19:15:36 -0700
commit90e7369484cd2e036c0e4915abf2a641b04b6dc1 (patch)
treec64688b6ac13ea7611976c8c98c4199906ce16ac /test
parenteed63fa267c712f608ea19dabd12359300b98028 (diff)
clang-format plus helpful comments
Diffstat (limited to 'test')
-rw-r--r--test/cpp/qps/client.h17
-rw-r--r--test/cpp/qps/client_async.cc5
-rw-r--r--test/cpp/qps/client_sync.cc13
-rw-r--r--test/cpp/qps/driver.cc13
4 files changed, 34 insertions, 14 deletions
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index c7513ed9b5..23993131cc 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -69,10 +69,12 @@ typedef std::chrono::time_point<grpc_time_source> grpc_time;
class Client {
public:
explicit Client(const ClientConfig& config)
- : channels_(config.client_channels()), timer_(new Timer), interarrival_timer_() {
+ : channels_(config.client_channels()),
+ timer_(new Timer),
+ interarrival_timer_() {
for (int i = 0; i < config.client_channels(); i++) {
channels_[i].init(config.server_targets(i % config.server_targets_size()),
- config);
+ config);
}
request_.set_response_type(grpc::testing::PayloadType::COMPRESSABLE);
request_.set_response_size(config.payload_size());
@@ -81,7 +83,7 @@ class Client {
ClientStats Mark() {
Histogram latencies;
- Histogram to_merge[threads_.size()]; // avoid std::vector for old compilers
+ Histogram to_merge[threads_.size()]; // avoid std::vector for old compilers
for (size_t i = 0; i < threads_.size(); i++) {
threads_[i]->BeginSwap(&to_merge[i]);
}
@@ -109,15 +111,22 @@ class Client {
class ClientChannelInfo {
public:
ClientChannelInfo() {}
- ClientChannelInfo(const ClientChannelInfo& i): channel_(), stub_() {
+ ClientChannelInfo(const ClientChannelInfo& i) : channel_(), stub_() {
+ // The copy constructor is to satisfy old compilers
+ // that need it for using std::vector . It is only ever
+ // used for empty entries
GPR_ASSERT(!i.channel_ && !i.stub_);
}
void init(const grpc::string& target, const ClientConfig& config) {
+ // We have to use a 2-phase init like this with a default
+ // constructor followed by an initializer function to make
+ // old compilers happy with using this in std::vector
channel_ = CreateTestChannel(target, config.enable_ssl());
stub_ = TestService::NewStub(channel_);
}
ChannelInterface* get_channel() { return channel_.get(); }
TestService::Stub* get_stub() { return stub_.get(); }
+
private:
std::shared_ptr<ChannelInterface> channel_;
std::unique_ptr<TestService::Stub> stub_;
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index 5e26400f06..a337610cbf 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -156,7 +156,7 @@ class AsyncClient : public Client {
std::function<ClientRpcContext*(int, TestService::Stub*,
const SimpleRequest&)> setup_ctx)
: Client(config),
- channel_lock_(new std::mutex[config.client_channels()]),
+ channel_lock_(new std::mutex[config.client_channels()]),
contexts_(config.client_channels()),
max_outstanding_per_channel_(config.outstanding_rpcs_per_channel()),
channel_count_(config.client_channels()),
@@ -337,7 +337,8 @@ class AsyncClient : public Client {
std::vector<boolean> issue_allowed_; // may this thread attempt to issue
std::vector<grpc_time> next_issue_; // when should it issue?
- std::mutex *channel_lock_; // a vector, but avoid std::vector for old compilers
+ std::mutex*
+ channel_lock_; // a vector, but avoid std::vector for old compilers
std::vector<context_list> contexts_; // per-channel list of idle contexts
int max_outstanding_per_channel_;
int channel_count_;
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 11c6daca1d..db5416a707 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -113,10 +113,10 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
public:
SynchronousStreamingClient(const ClientConfig& config)
- : SynchronousClient(config) {
+ : SynchronousClient(config) {
context_ = new grpc::ClientContext[num_threads_];
stream_ = new std::unique_ptr<
- grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>[num_threads_];
+ grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>[num_threads_];
for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) {
auto* stub = channels_[thread_idx % channels_.size()].get_stub();
stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]);
@@ -125,7 +125,8 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
}
~SynchronousStreamingClient() {
EndThreads();
- for (auto stream = &stream_[0]; stream != &stream_[num_threads_]; stream++) {
+ for (auto stream = &stream_[0]; stream != &stream_[num_threads_];
+ stream++) {
if (*stream) {
(*stream)->WritesDone();
EXPECT_TRUE((*stream)->Finish().ok());
@@ -149,9 +150,9 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
private:
// These are both conceptually std::vector but cannot be for old compilers
// that expect contained classes to support copy constructors
- grpc::ClientContext *context_;
- std::unique_ptr<
- grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>* stream_;
+ grpc::ClientContext* context_;
+ std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>*
+ stream_;
};
std::unique_ptr<Client> CreateSynchronousUnaryClient(
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 9cca4c04a1..71b0103fc7 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -79,6 +79,7 @@ static deque<string> get_hosts(const string& name) {
// Namespace for classes and functions used only in RunScenario
// Using this rather than local definitions to workaround gcc-4.4 limitations
+// regarding using templates without linkage
namespace runsc {
// ClientContext allocator
@@ -149,6 +150,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Start servers
using runsc::ServerData;
+ // servers is array rather than std::vector to avoid gcc-4.4 issues
+ // where class contained in std::vector must have a copy constructor
ServerData servers[num_servers];
for (size_t i = 0; i < num_servers; i++) {
servers[i].stub = std::move(Worker::NewStub(
@@ -157,7 +160,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
result_server_config = server_config;
result_server_config.set_host(workers[i]);
*args.mutable_setup() = server_config;
- servers[i].stream = std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts)));
+ servers[i].stream =
+ std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts)));
GPR_ASSERT(servers[i].stream->Write(args));
ServerStatus init_status;
GPR_ASSERT(servers[i].stream->Read(&init_status));
@@ -174,6 +178,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Start clients
using runsc::ClientData;
+ // clients is array rather than std::vector to avoid gcc-4.4 issues
+ // where class contained in std::vector must have a copy constructor
ClientData clients[num_clients];
for (size_t i = 0; i < num_clients; i++) {
clients[i].stub = std::move(Worker::NewStub(CreateChannel(
@@ -182,7 +188,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
result_client_config = client_config;
result_client_config.set_host(workers[i + num_servers]);
*args.mutable_setup() = client_config;
- clients[i].stream = std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts)));
+ clients[i].stream =
+ std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts)));
GPR_ASSERT(clients[i].stream->Write(args));
ClientStatus init_status;
GPR_ASSERT(clients[i].stream->Read(&init_status));
@@ -217,6 +224,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Wait some time
gpr_log(GPR_INFO, "Running");
+ // Use gpr_sleep_until rather than this_thread::sleep_until to support
+ // compilers that don't work with this_thread
gpr_sleep_until(gpr_time_add(
start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN)));