Index: /tests/SystemQueue-tests.cc
===================================================================
--- /tests/SystemQueue-tests.cc	(revision 12755)
+++ /tests/SystemQueue-tests.cc	(revision 12756)
@@ -3,4 +3,5 @@
 
 #include <unistd.h>  // usleep
+#include <boost/date_time.hpp> // local_time()
 
 #include <ostream>
@@ -9,4 +10,7 @@
 using namespace ariba::utility;
 using namespace std;
+
+using boost::posix_time::microsec_clock;
+
 
 /**
@@ -264,4 +268,6 @@
 /**
  *  This subclass has some special member functions suitable for timing tests
+ * 
+ *  NOTE: Timing tests are not always reproducable.. sorry. :-/
  */
 class SystemQueueTimingTest : 
@@ -277,5 +283,5 @@
  */
 #define DELAY_TIME 20  // ms
-#define DELAY_MARGIN 2000  // microseconds (1/1000 ms)
+#define DELAY_MARGIN 2000  // microseconds (1/1000 ms)   // TODO maybe this is too much..
 
 
@@ -299,4 +305,26 @@
         sysq.cancel();
     }
+    
+    
+    /**
+     * @param placed_in_queue The time (as ptime) when this event is put into the delay queue
+     * @param intended_sleep_time The time (in microseconds) the event is supposed to sleep in the queue
+     * @param margin The acceptable margin (in microseconds)
+     */
+    void TimeCheckingCall(ptime placed_in_queue, uint64_t intended_sleep_time, uint64_t margin)
+    {
+        ptime called_at = microsec_clock::local_time();
+        
+        // calculate actual sleep time and difference to intended sleep time
+        boost::posix_time::time_duration actual_sleep_time = called_at - placed_in_queue;
+        uint64_t diff = actual_sleep_time.total_microseconds() - intended_sleep_time;
+        
+        // info
+        cout << "/// Timing difference: " << diff << " microseconds" << endl;
+        
+        EXPECT_LT( abs(diff), margin );
+        
+        checkmark = true;
+    }
 
     SystemQueue& sysq;
@@ -315,5 +343,5 @@
 
     // noting to do until the delay is up..
-    usleep(DELAY_TIME + DELAY_MARGIN*10);  // XXX margin too high (TODO lower when SysQ is reimplemented)
+    usleep(DELAY_TIME*1000 + DELAY_MARGIN*10);  // XXX margin too high (TODO lower when SysQ is reimplemented)
     
     // wait for the event to happen
@@ -379,10 +407,10 @@
     // XXX the usual bug..
     sysq.scheduleCall(
-        boost::bind(&SystemQueueTest::Check, this),
+        boost::bind(&SystemQueueTimingTest::Check, this),
                     DELAY_TIME*4
     );
 
     // noting to do until the delay is up..
-    usleep(DELAY_TIME*4 + DELAY_MARGIN*100);  // XXX margin too high
+    usleep(DELAY_TIME * 4000 + DELAY_MARGIN*100);  // XXX margin too high
     
     // wait for the event to happen
@@ -392,2 +420,25 @@
     EXPECT_EQ( 4, last_ordered_call);
 }
+
+
+/**
+ *  Schedules a delayed call and test whether the sleep time is acurate
+ */
+TEST_F(SystemQueueTimingTest, TimingSingleCall)
+{
+    ptime now = microsec_clock::local_time();
+    
+    sysq.scheduleCall(
+        boost::bind(&SystemQueueTimingTest::TimeCheckingCall, this, 
+                    now, DELAY_TIME*1000, DELAY_MARGIN),
+        DELAY_TIME
+    );
+
+    // main thread is going to sleep..
+    usleep(DELAY_TIME * 1000 + DELAY_MARGIN * 2);
+    wait_for_checkmark(MAX_WAIT);
+    
+    // make sure the measurement function was called at all
+    EXPECT_TRUE(checkmark) << "Measurement function was NOT RUN AT ALL!";
+}
+
