forked from rethinkdb/rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.cc
More file actions
40 lines (27 loc) · 980 Bytes
/
timer_test.cc
File metadata and controls
40 lines (27 loc) · 980 Bytes
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
// Copyright 2010-2013 RethinkDB, all rights reserved.
#include "unittest/gtest.hpp"
#include "arch/timing.hpp"
#include "concurrency/pmap.hpp"
#include "unittest/unittest_utils.hpp"
#include "utils.hpp"
namespace unittest {
int wait_array[2][10] = { { 1, 1, 2, 3, 5, 13, 20, 30, 40, 8 },
{ 5, 3, 2, 40, 30, 20, 8, 13, 1, 1 } };
void walk_wait_times(int i) {
ticks_t t = get_ticks();
for (int j = 0; j < 10; ++j) {
nap(wait_array[i][j]);
const ticks_t t2 = get_ticks();
const int64_t diff = static_cast<int64_t>(t2) - static_cast<int64_t>(t);
// Asserts that we're off by less than two milliseconds.
ASSERT_LT(abs(diff - wait_array[i][j] * MILLION), 2 * MILLION);
t = t2;
}
}
void run_TestApproximateWaitTimes() {
pmap(2, walk_wait_times);
}
TEST(TimerTest, TestApproximateWaitTimes) {
unittest::run_in_thread_pool(run_TestApproximateWaitTimes);
}
} // namespace unittest