1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Copyright (C) 2016 Red Hat Inc.
12 #include "gtest/gtest.h"
15 #include "sim_client.h"
17 #include "test_dmclock.h"
20 using namespace std::placeholders;
22 namespace dmc = crimson::dmclock;
23 namespace test = crimson::test_dmc;
24 namespace sim = crimson::qos_simulation;
26 using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
28 static TimePoint now() { return std::chrono::system_clock::now(); }
31 TEST(test_client, full_bore_timing) {
32 std::atomic_ulong count(0);
34 ServerId server_id = 3;
36 sim::TestResponse resp(0);
37 dmc::PhaseType resp_params = dmc::PhaseType::priority;
38 test::DmcClient* client;
42 new test::DmcClient(ClientId(0),
43 [&] (const ServerId& server,
44 const sim::TestRequest& req,
45 const ClientId& client_id,
46 const dmc::ReqParams& req_params) {
48 client->receive_response(resp, client_id, resp_params);
50 [&] (const uint64_t seed) -> ServerId& {
53 test::dmc_client_accumulate_f,
56 5); // outstanding ops allowed
57 client->wait_until_done();
59 EXPECT_EQ(1000u, count) << "didn't get right number of ops";
61 int milliseconds = (end - start) / std::chrono::milliseconds(1);
62 EXPECT_LT(10000, milliseconds) << "timing too fast to be correct";
63 EXPECT_GT(12000, milliseconds) << "timing suspiciously slow";
69 TEST(test_client, paused_timing) {
70 std::atomic_ulong count(0);
71 std::atomic_ulong unresponded_count(0);
72 std::atomic_bool auto_respond(false);
74 ClientId my_client_id = 0;
75 ServerId server_id = 3;
77 sim::TestResponse resp(0);
78 dmc::PhaseType resp_params = dmc::PhaseType::priority;
79 test::DmcClient* client;
83 new test::DmcClient(my_client_id,
84 [&] (const ServerId& server,
85 const sim::TestRequest& req,
86 const ClientId& client_id,
87 const dmc::ReqParams& req_params) {
89 if (auto_respond.load()) {
90 client->receive_response(resp, client_id, resp_params);
95 [&] (const uint64_t seed) -> ServerId& {
98 test::dmc_client_accumulate_f,
102 50); // outstanding ops allowed
103 std::thread t([&]() {
104 std::this_thread::sleep_for(std::chrono::seconds(5));
105 EXPECT_EQ(50u, unresponded_count.load()) <<
106 "should have 50 unresponded calls";
108 // respond to those 50 calls
109 for(int i = 0; i < 50; ++i) {
110 client->receive_response(resp, my_client_id, resp_params);
115 client->wait_until_done();
117 int milliseconds = (end - start) / std::chrono::milliseconds(1);
119 // the 50 outstanding ops allowed means the first half-second of
120 // requests get responded to during the 5 second pause. So we have
121 // to adjust our expectations by a half-second.
122 EXPECT_LT(15000 - 500, milliseconds) << "timing too fast to be correct";
123 EXPECT_GT(17000 - 500, milliseconds) << "timing suspiciously slow";