1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*
// vim: ts=8 sw=2 smarttab
#pragma once
#include <unistd.h>
#include <chrono>
#include <map>
#include <string>
#include <thread>
#include "include/buffer_fwd.h"
// helpers shared by librados tests
std::string get_temp_pool_name(const std::string &prefix = "test-rados-api-");
void assert_eq_sparse(ceph::bufferlist& expected,
const std::map<uint64_t, uint64_t>& extents,
ceph::bufferlist& actual);
class TestAlarm
{
public:
#ifndef _WIN32
TestAlarm() {
alarm(1200);
}
~TestAlarm() {
alarm(0);
}
#else
// TODO: add a timeout mechanism for Windows as well, possibly by using
// CreateTimerQueueTimer.
TestAlarm() {
}
~TestAlarm() {
}
#endif
};
template<class Rep, class Period, typename Func, typename... Args,
typename Return = std::result_of_t<Func&&(Args&&...)>>
Return wait_until(const std::chrono::duration<Rep, Period>& rel_time,
const std::chrono::duration<Rep, Period>& step,
const Return& expected,
Func&& func, Args&&... args)
{
std::this_thread::sleep_for(rel_time - step);
for (auto& s : {step, step}) {
if (!s.count()) {
break;
}
auto ret = func(std::forward<Args>(args)...);
if (ret == expected) {
return ret;
}
std::this_thread::sleep_for(s);
}
return func(std::forward<Args>(args)...);
}
|