Skip to content

Commit

Permalink
Simplify and properly implement openloop testing.
Browse files Browse the repository at this point in the history
Revive it in tests as well
  • Loading branch information
vjpai committed Feb 11, 2016
1 parent d472ad2 commit 1132c6b
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 310 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,8 @@ test_cxx: test_zookeeper buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/interop_test || ( echo test interop_test failed ; exit 1 )
$(E) "[RUN] Testing mock_test"
$(Q) $(BINDIR)/$(CONFIG)/mock_test || ( echo test mock_test failed ; exit 1 )
$(E) "[RUN] Testing qps_openloop_test"
$(Q) $(BINDIR)/$(CONFIG)/qps_openloop_test || ( echo test qps_openloop_test failed ; exit 1 )
$(E) "[RUN] Testing qps_test"
$(Q) $(BINDIR)/$(CONFIG)/qps_test || ( echo test qps_test failed ; exit 1 )
$(E) "[RUN] Testing secure_auth_context_test"
Expand Down
1 change: 0 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,6 @@ targets:
- posix
- name: qps_openloop_test
build: test
run: false
language: c++
src:
- test/cpp/qps/qps_openloop_test.cc
Expand Down
44 changes: 10 additions & 34 deletions test/cpp/qps/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <grpc++/support/byte_buffer.h>
#include <grpc++/support/slice.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>

#include "src/proto/grpc/testing/payloads.grpc.pb.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
Expand All @@ -52,27 +53,8 @@
#include "test/cpp/util/create_test_channel.h"

namespace grpc {

#if defined(__APPLE__)
// Specialize Timepoint for high res clock as we need that
template <>
class TimePoint<std::chrono::high_resolution_clock::time_point> {
public:
TimePoint(const std::chrono::high_resolution_clock::time_point& time) {
TimepointHR2Timespec(time, &time_);
}
gpr_timespec raw_time() const { return time_; }

private:
gpr_timespec time_;
};
#endif

namespace testing {

typedef std::chrono::high_resolution_clock grpc_time_source;
typedef std::chrono::time_point<grpc_time_source> grpc_time;

template <class RequestType>
class ClientRequestCreator {
public:
Expand Down Expand Up @@ -218,26 +200,20 @@ class Client {
closed_loop_ = false;
// set up interarrival timer according to random dist
interarrival_timer_.init(*random_dist, num_threads);
auto now = grpc_time_source::now();
auto now = gpr_now(GPR_CLOCK_MONOTONIC);
for (size_t i = 0; i < num_threads; i++) {
next_time_.push_back(
now +
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_.next(i)));
gpr_time_add(now, gpr_time_from_nanos(interarrival_timer_.next(i), GPR_TIMESPAN)));
}
}
}

bool NextIssueTime(int thread_idx, grpc_time* time_delay) {
if (closed_loop_) {
return false;
} else {
*time_delay = next_time_[thread_idx];
next_time_[thread_idx] +=
std::chrono::duration_cast<grpc_time_source::duration>(
interarrival_timer_.next(thread_idx));
return true;
}
gpr_timespec NextIssueTime(int thread_idx) {
gpr_timespec result = next_time_[thread_idx];
next_time_[thread_idx] =
gpr_time_add(next_time_[thread_idx],
gpr_time_from_nanos(interarrival_timer_.next(thread_idx), GPR_TIMESPAN));
return result;
}

private:
Expand Down Expand Up @@ -315,7 +291,7 @@ class Client {
std::unique_ptr<Timer> timer_;

InterarrivalTimer interarrival_timer_;
std::vector<grpc_time> next_time_;
std::vector<gpr_timespec> next_time_;
};

template <class StubType, class RequestType>
Expand Down
Loading

0 comments on commit 1132c6b

Please sign in to comment.