blob: 478d749e15d75d2f58141ba8366908b0028639a4 (
plain) (
blame)
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/time/time_box.h>
TEST("require that long-lived timebox returns falling time left numbers") {
vespalib::TimeBox box(3600);
double last_timeLeft = box.timeLeft();
for (int i = 0; i < 10; i++) {
EXPECT_TRUE(box.hasTimeLeft());
double timeLeft = box.timeLeft();
EXPECT_TRUE(timeLeft <= last_timeLeft);
last_timeLeft = timeLeft;
FastOS_Thread::Sleep(10);
}
}
TEST("require that short-lived timebox times out") {
vespalib::TimeBox box(0.125);
FastOS_Thread::Sleep(150);
EXPECT_FALSE(box.hasTimeLeft());
EXPECT_EQUAL(box.timeLeft(), 0.0);
}
TEST("require that short-lived timebox always returns at least minimum time") {
vespalib::TimeBox box(0.250, 0.125);
for (int i = 0; i < 10; i++) {
double timeLeft = box.timeLeft();
EXPECT_TRUE(timeLeft <= 0.250);
EXPECT_TRUE(timeLeft >= 0.125);
FastOS_Thread::Sleep(30);
}
EXPECT_FALSE(box.hasTimeLeft());
EXPECT_EQUAL(box.timeLeft(), 0.125);
}
TEST_MAIN() { TEST_RUN_ALL(); }
|