Commit db453a5b authored by Brian Gesiak's avatar Brian Gesiak Committed by Facebook Github Bot

Fix Coro.Sleep test for opt builds

Summary:
Optimized builds of //folly/experimental/coro test Coro.Sleep
would almost always fail because the compiler would generate
code that would only sleep for 0.98 seconds. Perform some
simple rounding in order to ignore slight optimizations like
these.

Reviewed By: wqfish

Differential Revision: D7496416

fbshipit-source-id: f81ff30922fbf3e5d2086fde50f4a469bdf72e51
parent dad687f7
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#if FOLLY_HAS_COROUTINES #if FOLLY_HAS_COROUTINES
#include <folly/Chrono.h>
#include <folly/executors/ManualExecutor.h> #include <folly/executors/ManualExecutor.h>
#include <folly/experimental/coro/Future.h> #include <folly/experimental/coro/Future.h>
#include <folly/io/async/ScopedEventBaseThread.h> #include <folly/io/async/ScopedEventBaseThread.h>
...@@ -82,8 +83,13 @@ TEST(Coro, Sleep) { ...@@ -82,8 +83,13 @@ TEST(Coro, Sleep) {
future.wait(); future.wait();
// The total time should be roughly 1 second. Some builds, especially
// optimized ones, may result in slightly less than 1 second, so we perform
// rounding here.
auto totalTime = std::chrono::steady_clock::now() - startTime;
EXPECT_GE( EXPECT_GE(
std::chrono::steady_clock::now() - startTime, std::chrono::seconds{1}); chrono::round<std::chrono::seconds>(totalTime), std::chrono::seconds{1});
EXPECT_TRUE(future.await_ready()); EXPECT_TRUE(future.await_ready());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment