summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/tests/clock/clock_test.cpp
blob: b5650244a45b1d6caa02ec04b8a3c4fa0413996e (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
// Copyright 2017 Yahoo Holdings. 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/time.h>
#include <vespa/fastos/thread.h>

using vespalib::Clock;
using fastos::TimeStamp;


TEST("Test that clock is ticking forward") {

    Clock clock(0.050);
    FastOS_ThreadPool pool(0x10000);
    ASSERT_TRUE(pool.NewThread(clock.getRunnable(), nullptr) != nullptr);
    fastos::SteadyTimeStamp start = clock.getTimeNS();
    std::this_thread::sleep_for(5s);
    fastos::SteadyTimeStamp stop = clock.getTimeNS();
    EXPECT_TRUE(stop > start);
    std::this_thread::sleep_for(6s);
    clock.stop();
    fastos::SteadyTimeStamp stop2 = clock.getTimeNS();
    EXPECT_TRUE(stop2 > stop);
    EXPECT_TRUE((stop2 - stop)/TimeStamp::MICRO > 1000);
}

TEST_MAIN() { TEST_RUN_ALL(); }