Readd unit test
authorAndrei Bajenov <andreib@fb.com>
Mon, 1 Dec 2014 21:52:38 +0000 (13:52 -0800)
committerDave Watson <davejwatson@fb.com>
Thu, 11 Dec 2014 15:59:09 +0000 (07:59 -0800)
Summary:
Description:
Last time a merge error broke stuff, fixing and readding

Test Plan:
Ran unit test

This reverts commit 1075ab9d6f62cad36a228bd3fc7203a75fdf5baf.

Reviewed By: davejwatson@fb.com

Subscribers: njormrod, folly-diffs@, wstefancik

FB internal diff: D1695920

Signature: t1:1695920:1416529609:3f726ac5df4e33f254075738ea6655a6fc01bb7f

folly/io/async/test/HHWheelTimerTest.cpp

index 286d89153ace8968fa65ce6584a213e1eecbc8d8..ddc9b4e6b27db7d0f94a7fc0521f0253e286694f 100644 (file)
@@ -96,6 +96,32 @@ TEST(HHWheelTimerTest, FireOnce) {
   T_CHECK_TIMEOUT(start, end, milliseconds(10));
 }
 
+/*
+ * Test scheduling a timeout from another timeout callback.
+ */
+TEST(HHWheelTimerTest, TestSchedulingWithinCallback) {
+  EventBase eventBase;
+  StackWheelTimer t(&eventBase, milliseconds(10));
+  const HHWheelTimer::Callback* nullCallback = nullptr;
+
+  TestTimeout t1;
+  // Delayed to simulate the steady_clock counter lagging
+  TestTimeoutDelayed t2;
+
+  t.scheduleTimeout(&t1, milliseconds(500));
+  t1.fn = [&] { t.scheduleTimeout(&t2, milliseconds(1)); };
+  // If t is in an inconsistent state, detachEventBase should fail.
+  t2.fn = [&] { t.detachEventBase(); };
+
+  ASSERT_EQ(t.count(), 1);
+
+  eventBase.loop();
+
+  ASSERT_EQ(t.count(), 0);
+  ASSERT_EQ(t1.timestamps.size(), 1);
+  ASSERT_EQ(t2.timestamps.size(), 1);
+}
+
 /*
  * Test cancelling a timeout when it is scheduled to be fired right away.
  */