Commit b8147234 authored by Hans Fugal's avatar Hans Fugal Committed by Sara Golemon

minor Timekeeper bug

Summary: Fix so `Timekeeper::at(now() - something)` works. Also introduce a test which explicitly tests when <= now codepath, which wasn't broken per se here, but which test also tickled this bug.

Reviewed By: @jsedgwick

Differential Revision: D2209166
parent 83e4f1b3
...@@ -46,6 +46,9 @@ template <class> class Future; ...@@ -46,6 +46,9 @@ template <class> class Future;
/// over Duration. This makes the code more legible and means you won't be /// over Duration. This makes the code more legible and means you won't be
/// unpleasantly surprised if we redefine Duration to microseconds, or /// unpleasantly surprised if we redefine Duration to microseconds, or
/// something. /// something.
///
/// timekeeper.after(std::chrono::duration_cast<Duration>(
/// someNanoseconds))
class Timekeeper { class Timekeeper {
public: public:
virtual ~Timekeeper() = default; virtual ~Timekeeper() = default;
...@@ -89,7 +92,7 @@ Future<Unit> Timekeeper::at(std::chrono::time_point<Clock> when) { ...@@ -89,7 +92,7 @@ Future<Unit> Timekeeper::at(std::chrono::time_point<Clock> when) {
return makeFuture(); return makeFuture();
} }
return after(when - now); return after(std::chrono::duration_cast<Duration>(when - now));
} }
} // namespace folly } // namespace folly
...@@ -198,3 +198,16 @@ TEST(Timekeeper, onTimeoutPropagates) { ...@@ -198,3 +198,16 @@ TEST(Timekeeper, onTimeoutPropagates) {
EXPECT_TRUE(flag); EXPECT_TRUE(flag);
} }
*/ */
TEST_F(TimekeeperFixture, atBeforeNow) {
auto f = timeLord_->at(now() - too_long);
EXPECT_TRUE(f.isReady());
EXPECT_FALSE(f.hasException());
}
TEST_F(TimekeeperFixture, howToCastDuration) {
// I'm not sure whether this rounds up or down but it's irrelevant for the
// purpose of this example.
auto f = timeLord_->after(std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(1)));
}
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