From 24e91815c144fcbcaa38aef43ab582a395d08b5b Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Fri, 29 Jul 2016 14:28:53 -0700 Subject: [PATCH] More tests 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 | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 457cf831..e4f74211 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -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. */ -- 2.34.1