summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/clock/clock_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/tests/clock/clock_test.cpp')
-rw-r--r--vespalib/src/tests/clock/clock_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/vespalib/src/tests/clock/clock_test.cpp b/vespalib/src/tests/clock/clock_test.cpp
new file mode 100644
index 00000000000..f2de085da84
--- /dev/null
+++ b/vespalib/src/tests/clock/clock_test.cpp
@@ -0,0 +1,29 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/clock.h>
+#include <vespa/vespalib/util/invokeserviceimpl.h>
+#include <thread>
+
+using vespalib::Clock;
+using vespalib::duration;
+using vespalib::steady_time;
+using vespalib::steady_clock;
+
+void waitForMovement(steady_time start, Clock & clock, vespalib::duration timeout) {
+ steady_time startOsClock = steady_clock::now();
+ while ((clock.getTimeNS() <= start) && ((steady_clock::now() - startOsClock) < timeout)) {
+ std::this_thread::sleep_for(1ms);
+ }
+}
+
+TEST("Test that clock is ticking forward") {
+ vespalib::InvokeServiceImpl invoker(50ms);
+ Clock clock(invoker.nowRef());
+ steady_time start = clock.getTimeNS();
+ waitForMovement(start, clock, 10s);
+ steady_time stop = clock.getTimeNS();
+ EXPECT_TRUE(stop > start);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file