Summary: When timekeeper singleton no longer exists during shutdown and folly::Singleton::try_get() can return nullptr, make sure nullptr is handled gracefully.
Reviewed By: yfeldblum
Differential Revision:
D6101311
fbshipit-source-id:
fefeddfbd048d1a7632688bb3526db15b685dd72
}
std::shared_ptr<Timekeeper> tks;
- if (!tk) {
+ if (LIKELY(!tk)) {
tks = folly::detail::getTimekeeperSingleton();
- tk = DCHECK_NOTNULL(tks.get());
+ tk = tks.get();
+ }
+
+ if (UNLIKELY(!tk)) {
+ return makeFuture<T>(NoTimekeeper());
}
auto ctx = std::make_shared<Context>(std::move(e));
EXPECT_THROW(futures::sleep(one_ms).get(), NoTimekeeper);
}
+TEST(Timekeeper, futureWithinHandlesNullTimekeeperSingleton) {
+ Singleton<ThreadWheelTimekeeper>::make_mock([] { return nullptr; });
+ SCOPE_EXIT {
+ Singleton<ThreadWheelTimekeeper>::make_mock();
+ };
+ Promise<int> p;
+ auto f = p.getFuture().within(one_ms);
+ EXPECT_THROW(f.get(), NoTimekeeper);
+}
+
TEST(Timekeeper, futureDelayed) {
auto t1 = now();
auto dur = makeFuture()