Scheduler: Fix timer scheduling delay unit-test
g0dil [Fri, 15 May 2009 18:47:20 +0000 (18:47 +0000)]
Scheduler: Fix EventHook API

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1208 270642c3-0616-0410-b53a-bc976706d245

Scheduler/EventHook.cci
Scheduler/EventHook.hh
Scheduler/Scheduler.test.cc
Scheduler/TimerEvent.test.cc

index 89e1b1a..8cbec85 100644 (file)
@@ -34,8 +34,8 @@
 // senf::scheduler::EventHook
 
 prefix_ senf::scheduler::EventHook::EventHook(std::string const & name, Callback const & cb,
-                                                bool initiallyEnabled,
-                                                detail::FIFORunner::TaskInfo::Priority priority)
+                                              detail::FIFORunner::TaskInfo::Priority priority,
+                                              bool initiallyEnabled)
     : detail::FIFORunner::TaskInfo(name, priority), cb_ (cb)
 {
     if (initiallyEnabled)
index 4437780..0ab24c9 100644 (file)
@@ -82,7 +82,7 @@ namespace scheduler {
         ///@{
 
         EventHook(std::string const & name, Callback const & cb,
-                   bool initiallyEnabled = true, Priority priority = POST);
+                  Priority priority, bool initiallyEnabled = true);
                                         ///< Register an event hook
                                         /**< Registers \a cb to be called whenever any other event
                                              is signaled by the scheduler. If \a initiallyEnabled is
index 0a13518..14e01bc 100644 (file)
@@ -242,8 +242,8 @@ void schedulerTest()
 
     ///////////////////////////////////////////////////////////////////////////
 
-    senf::scheduler::EventHook evev ("eventCounter", eventeventhandler, true,
-                                      senf::scheduler::EventHook::PRE);
+    senf::scheduler::EventHook evev ("eventCounter", eventeventhandler,
+                                     senf::scheduler::EventHook::PRE);
 
     {
         senf::scheduler::FdEvent fde1 ("testFdEvent", boost::bind(&callback, sock, _1),
index ff410e9..7801ad1 100644 (file)
@@ -96,24 +96,37 @@ namespace {
 
     unsigned count (0);
     senf::ClockService::clock_type delay (0);
+    bool haveCb (false);
 
     void jitterCb(senf::scheduler::TimerEvent & tm)
     {
         std::cerr << senf::scheduler::now() << ' ' << tm.timeout() << '\n';
         count ++;
         delay += senf::scheduler::now() - tm.timeout();
+        haveCb = true;
         tm.timeout(randomDelay());
     }
 
-    void logSchedulerTime()
+    void preCb()
     {
-        std::cerr << senf::scheduler::now() << '\n';
+        haveCb = false;
+    }
+
+    void postCb()
+    {
+        if (! haveCb)
+            std::cerr << senf::scheduler::now() << '\n';
     }
 
     void jitterTest()
     {
         count = 0;
         delay = 0;
+        senf::scheduler::EventHook pre ("jitterTest::preCb", &preCb,
+                                        senf::scheduler::EventHook::PRE);
+        senf::scheduler::EventHook post ("jitterTest::postCb", &postCb,
+                                         senf::scheduler::EventHook::POST);
+
         senf::scheduler::TimerEvent tm1 ("jitterTest::tm1", boost::bind(&jitterCb, boost::ref(tm1)),
                                          randomDelay());
         senf::scheduler::TimerEvent tm2 ("jitterTest::tm2", boost::bind(&jitterCb, boost::ref(tm2)),
@@ -124,9 +137,6 @@ namespace {
         senf::scheduler::TimerEvent timeout("jitterTest::timeout", &senf::scheduler::terminate,
                                             senf::scheduler::now() + senf::ClockService::seconds(5));
 
-        senf::scheduler::EventHook timerCalled ("jitterTest::logSchedulerTime", &logSchedulerTime,
-                                                senf::scheduler::EventHook::PRE);
-
         senf::scheduler::process();
 
         std::cerr << "Average scheduling delay: " << delay/count << "\n";