summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/tests/timer/timer_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'staging_vespalib/src/tests/timer/timer_test.cpp')
-rw-r--r--staging_vespalib/src/tests/timer/timer_test.cpp40
1 files changed, 19 insertions, 21 deletions
diff --git a/staging_vespalib/src/tests/timer/timer_test.cpp b/staging_vespalib/src/tests/timer/timer_test.cpp
index 9d04500b8cd..1f0ee81e4e6 100644
--- a/staging_vespalib/src/tests/timer/timer_test.cpp
+++ b/staging_vespalib/src/tests/timer/timer_test.cpp
@@ -2,18 +2,15 @@
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/util/scheduledexecutor.h>
+#include <vespa/vespalib/util/size_literals.h>
+#include <vespa/fnet/transport.h>
+#include <vespa/fastos/thread.h>
using namespace vespalib;
using vespalib::Executor;
typedef Executor::Task Task;
-class Test : public TestApp
-{
-public:
- int Main() override;
- void testScheduling();
- void testReset();
-};
+namespace {
class TestTask : public Task {
private:
@@ -23,35 +20,36 @@ public:
void run() override { _latch.countDown(); }
};
-int
-Test::Main()
-{
- TEST_INIT("timer_test");
- testScheduling();
- testReset();
- TEST_DONE();
}
-void Test::testScheduling()
-{
+TEST("testScheduling") {
vespalib::CountDownLatch latch1(3);
vespalib::CountDownLatch latch2(2);
- ScheduledExecutor timer;
+ FastOS_ThreadPool threadPool(64_Ki);
+ FNET_Transport transport;
+ transport.Start(&threadPool);
+ ScheduledExecutor timer(transport);
timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 100ms, 200ms);
timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch2), 500ms, 500ms);
EXPECT_TRUE(latch1.await(60s));
EXPECT_TRUE(latch2.await(60s));
+ timer.reset();
+ transport.ShutDown(true);
}
-void Test::testReset()
-{
+TEST("testReset") {
vespalib::CountDownLatch latch1(2);
- ScheduledExecutor timer;
+ FastOS_ThreadPool threadPool(64_Ki);
+ FNET_Transport transport;
+ transport.Start(&threadPool);
+ ScheduledExecutor timer(transport);
timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 2s, 3s);
timer.reset();
EXPECT_TRUE(!latch1.await(3s));
timer.scheduleAtFixedRate(std::make_unique<TestTask>(latch1), 200ms, 300ms);
EXPECT_TRUE(latch1.await(60s));
+ timer.reset();
+ transport.ShutDown(true);
}
-TEST_APPHOOK(Test)
+TEST_MAIN() { TEST_RUN_ALL(); }