From a5a5daef1f43d6222a0261e856edd3a62f2c7b24 Mon Sep 17 00:00:00 2001 From: Maxim Georgiev Date: Mon, 24 Aug 2015 18:46:35 -0700 Subject: [PATCH] Adding a unit test for HHWheelTimer exercising the default timeout functionality. Summary: Recently default timeout logic was added to HHWheelTimer interface. This diff adds a unit test exercising this new logic. Reviewed By: @djwatson Differential Revision: D2376834 --- folly/io/async/test/HHWheelTimerTest.cpp | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 6cabc028..695b6e7d 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -389,6 +389,41 @@ TEST_F(HHWheelTimerTest, SlowLoop) { T_CHECK_TIMEOUT(start2, end2, milliseconds(10), milliseconds(1)); } +/* + * Test scheduling a mix of timers with default timeout and variable timeout. + */ +TEST_F(HHWheelTimerTest, DefaultTimeout) { + milliseconds defaultTimeout(milliseconds(5)); + StackWheelTimer t(&eventBase, + milliseconds(1), + AsyncTimeout::InternalEnum::NORMAL, + defaultTimeout); + + TestTimeout t1; + TestTimeout t2; + + ASSERT_EQ(t.count(), 0); + ASSERT_EQ(t.getDefaultTimeout(), defaultTimeout); + + t.scheduleTimeout(&t1); + t.scheduleTimeout(&t2, milliseconds(10)); + + 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); + + T_CHECK_TIMEOUT(start, t1.timestamps[0], defaultTimeout); + T_CHECK_TIMEOUT(start, t2.timestamps[0], milliseconds(10)); + T_CHECK_TIMEOUT(start, end, milliseconds(10)); +} + TEST_F(HHWheelTimerTest, lambda) { StackWheelTimer t(&eventBase, milliseconds(1)); size_t count = 0; -- 2.34.1