From: Haijun Zhu Date: Mon, 23 Nov 2015 22:25:47 +0000 (-0800) Subject: Fix HHWheelTimerTest.AtMostEveryN X-Git-Tag: deprecate-dynamic-initializer~237 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aba93096336d84d7862e2c8e17b8d5806457edf0;p=folly.git Fix HHWheelTimerTest.AtMostEveryN Summary: If it takes too long to finish it is probably heavily loaded. Skip if so. Reviewed By: mmcduff Differential Revision: D2687346 fb-gh-sync-id: 282cac7e4df361f714de1089f11b098af79b1512 --- diff --git a/folly/io/async/test/HHWheelTimerTest.cpp b/folly/io/async/test/HHWheelTimerTest.cpp index 30ee8e90..3b6d4d8e 100644 --- a/folly/io/async/test/HHWheelTimerTest.cpp +++ b/folly/io/async/test/HHWheelTimerTest.cpp @@ -265,7 +265,7 @@ TEST_F(HHWheelTimerTest, AtMostEveryN) { StackWheelTimer t(&eventBase, atMostEveryN); t.setCatchupEveryN(70); - // Create 60 timeouts to be added to ts10 at 1ms intervals. + // Create 60 timeouts to be added to ts1 at 1ms intervals. uint32_t numTimeouts = 60; std::vector timeouts(numTimeouts); @@ -280,7 +280,7 @@ TEST_F(HHWheelTimerTest, AtMostEveryN) { // Call timeoutExpired() on the timeout so it will record a timestamp. // This is done only so we can record when we scheduled the timeout. // This way if ts1 starts to fall behind a little over time we will still - // be comparing the ts10 timeouts to when they were first scheduled (rather + // be comparing the ts1 timeouts to when they were first scheduled (rather // than when we intended to schedule them). The scheduler may fall behind // eventually since we don't really schedule it once every millisecond. // Each time it finishes we schedule it for 1 millisecond in the future. @@ -302,6 +302,14 @@ TEST_F(HHWheelTimerTest, AtMostEveryN) { eventBase.loop(); TimePoint end; + // This should take roughly 2*60 + 25 ms to finish. If it takes more than + // 250 ms to finish the system is probably heavily loaded, so skip. + if (std::chrono::duration_cast( + end.getTime() - start.getTime()).count() > 250) { + LOG(WARNING) << "scheduling all timeouts takes too long"; + return; + } + // We scheduled timeouts 1ms apart, when the HHWheelTimer is only allowed // to wake up at most once every 3ms. It will therefore wake up every 3ms // and fire groups of approximately 3 timeouts at a time.