aboutsummaryrefslogtreecommitdiffstats
path: root/fnet/src/tests/scheduling/sloweventloop.cpp
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /fnet/src/tests/scheduling/sloweventloop.cpp
Publish
Diffstat (limited to 'fnet/src/tests/scheduling/sloweventloop.cpp')
-rw-r--r--fnet/src/tests/scheduling/sloweventloop.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/fnet/src/tests/scheduling/sloweventloop.cpp b/fnet/src/tests/scheduling/sloweventloop.cpp
new file mode 100644
index 00000000000..3e27bfef131
--- /dev/null
+++ b/fnet/src/tests/scheduling/sloweventloop.cpp
@@ -0,0 +1,65 @@
+// 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/fnet/fnet.h>
+
+
+class MyTask : public FNET_Task
+{
+public:
+ bool _done;
+
+ MyTask(FNET_Scheduler &scheduler)
+ : FNET_Task(&scheduler),
+ _done(false) {}
+
+ bool done() const { return _done; }
+ void PerformTask() { _done = true; }
+};
+
+
+TEST("slow event loop") {
+ FastOS_Time t;
+ t.SetMilliSecs(0);
+
+ FNET_Scheduler scheduler(&t, &t);
+ MyTask task(scheduler);
+ MyTask task2(scheduler);
+
+ scheduler.CheckTasks();
+ t.AddMilliSecs(10000);
+ task.Schedule(5.0);
+
+ uint32_t cnt = 0;
+ for (;;) {
+ scheduler.CheckTasks();
+ if (task.done()) {
+ break;
+ }
+ ++cnt;
+ t.AddMilliSecs(1);
+ }
+
+ if (!EXPECT_TRUE(cnt > 4700 && cnt < 4800)) {
+ fprintf(stderr, "cnt=%d\n", cnt);
+ }
+
+ scheduler.CheckTasks();
+ t.AddMilliSecs(10000);
+ task2.Schedule(5.0);
+
+ uint32_t cnt2 = 0;
+ for(;;) {
+ scheduler.CheckTasks();
+ if (task2.done()) {
+ break;
+ }
+ ++cnt2;
+ t.AddMilliSecs(10000);
+ }
+
+ if (!EXPECT_TRUE(cnt2 > 15 && cnt2 < 25)) {
+ fprintf(stderr, "cnt2=%d\n", cnt2);
+ }
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }