]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dmclock/test/test_test_client.cc
11cbd74b15777ab4631b86bf3d2f4fe5b359acc9
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Copyright (C) 2016 Red Hat Inc.
7 * Author: J. Eric Ivancich <ivancich@redhat.com>
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License version
11 * 2.1, as published by the Free Software Foundation. See file
21 #include "gtest/gtest.h"
24 #include "sim_client.h"
26 #include "test_dmclock.h"
29 using namespace std::placeholders
;
31 namespace dmc
= crimson::dmclock
;
32 namespace test
= crimson::test_dmc
;
33 namespace sim
= crimson::qos_simulation
;
35 using TimePoint
= std::chrono::time_point
<std::chrono::system_clock
>;
37 static TimePoint
now() { return std::chrono::system_clock::now(); }
40 TEST(test_client
, full_bore_timing
) {
41 std::atomic_ulong
count(0);
43 ServerId server_id
= 3;
45 sim::TestResponse
resp(0);
46 dmc::PhaseType resp_params
= dmc::PhaseType::priority
;
47 test::DmcClient
* client
;
48 const sim::Cost request_cost
= 1u;
52 new test::DmcClient(ClientId(0),
53 [&] (const ServerId
& server
,
54 const sim::TestRequest
& req
,
55 const ClientId
& client_id
,
56 const dmc::ReqParams
& req_params
) {
58 client
->receive_response(resp
, client_id
, resp_params
, request_cost
);
60 [&] (const uint64_t seed
) -> ServerId
& {
63 test::dmc_client_accumulate_f
,
66 5); // outstanding ops allowed
67 client
->wait_until_done();
69 EXPECT_EQ(1000u, count
) << "didn't get right number of ops";
71 int milliseconds
= (end
- start
) / std::chrono::milliseconds(1);
72 EXPECT_LT(10000, milliseconds
) << "timing too fast to be correct";
73 EXPECT_GT(12000, milliseconds
) << "timing suspiciously slow";
79 TEST(test_client
, paused_timing
) {
80 std::atomic_ulong
count(0);
81 std::atomic_ulong
unresponded_count(0);
82 std::atomic_bool
auto_respond(false);
84 ClientId my_client_id
= 0;
85 ServerId server_id
= 3;
87 sim::TestResponse
resp(0);
88 dmc::PhaseType resp_params
= dmc::PhaseType::priority
;
89 const uint64_t request_cost
= 1u;
90 test::DmcClient
* client
;
94 new test::DmcClient(my_client_id
,
95 [&] (const ServerId
& server
,
96 const sim::TestRequest
& req
,
97 const ClientId
& client_id
,
98 const dmc::ReqParams
& req_params
) {
100 if (auto_respond
.load()) {
101 client
->receive_response(resp
, client_id
, resp_params
, request_cost
);
106 [&] (const uint64_t seed
) -> ServerId
& {
109 test::dmc_client_accumulate_f
,
113 50); // outstanding ops allowed
114 std::thread
t([&]() {
115 std::this_thread::sleep_for(std::chrono::seconds(5));
116 EXPECT_EQ(50u, unresponded_count
.load()) <<
117 "should have 50 unresponded calls";
119 // respond to those 50 calls
120 for(int i
= 0; i
< 50; ++i
) {
121 client
->receive_response(resp
, my_client_id
, resp_params
, 1);
126 client
->wait_until_done();
128 int milliseconds
= (end
- start
) / std::chrono::milliseconds(1);
130 // the 50 outstanding ops allowed means the first half-second of
131 // requests get responded to during the 5 second pause. So we have
132 // to adjust our expectations by a half-second.
133 EXPECT_LT(15000 - 500, milliseconds
) << "timing too fast to be correct";
134 EXPECT_GT(17000 - 500, milliseconds
) << "timing suspiciously slow";