More tests
authorDave Watson <davejwatson@fb.com>
Fri, 29 Jul 2016 21:28:53 +0000 (14:28 -0700)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Fri, 29 Jul 2016 21:38:33 +0000 (14:38 -0700)
Summary:
Test timers where we need to reschedule the wheel timer next tick.

This wasn't tested before, since we were always ticking, and never needed to reschedule.

Differential Revision: D3637103

fbshipit-source-id: cb80e7b790bb6aac68bdb5f60f8aa00caa2e5b69

folly/io/async/test/HHWheelTimerTest.cpp

index 457cf8313bb0ccbc3a3d0f8499da7aa38eba6729..e4f74211a9ba0d34e4999053657f9dafa2f1cb3d 100644 (file)
@@ -390,6 +390,36 @@ TEST_F(HHWheelTimerTest, SlowLoop) {
   T_CHECK_TIMEOUT(start2, end2, milliseconds(10), milliseconds(1));
 }
 
+/*
+ * Test an event scheduled before the last event fires on time
+ */
+
+TEST_F(HHWheelTimerTest, SlowFast) {
+  HHWheelTimer& t = eventBase.timer();
+
+  TestTimeout t1;
+  TestTimeout t2;
+
+  ASSERT_EQ(t.count(), 0);
+
+  t.scheduleTimeout(&t1, milliseconds(10));
+  t.scheduleTimeout(&t2, milliseconds(5));
+
+  ASSERT_EQ(t.count(), 2);
+
+  TimePoint start;
+  eventBase.loop();
+  TimePoint end;
+
+  ASSERT_EQ(t1.timestamps.size(), 1);
+  ASSERT_EQ(t2.timestamps.size(), 1);
+  ASSERT_EQ(t.count(), 0);
+
+  // Check that the timeout was delayed by sleep
+  T_CHECK_TIMEOUT(start, t1.timestamps[0], milliseconds(10), milliseconds(1));
+  T_CHECK_TIMEOUT(start, t2.timestamps[0], milliseconds(5), milliseconds(1));
+}
+
 /*
  * Test scheduling a mix of timers with default timeout and variable timeout.
  */