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
/// over Duration. This makes the code more legible and means you won't be
/// unpleasantly surprised if we redefine Duration to microseconds, or
/// something.
+///
+/// timekeeper.after(std::chrono::duration_cast<Duration>(
+/// someNanoseconds))
class Timekeeper {
public:
virtual ~Timekeeper() = default;
return makeFuture();
}
- return after(when - now);
+ return after(std::chrono::duration_cast<Duration>(when - now));
}
} // namespace folly
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)));
+}