From d904cfb90748db6f792291b9e84cd87ce26a9d50 Mon Sep 17 00:00:00 2001 From: Andrei Bajenov Date: Mon, 1 Dec 2014 13:52:38 -0800 Subject: [PATCH] Readd unit test 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 | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 286d8915..ddc9b4e6 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -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. */ -- 2.34.1