| #include <gtest/gtest.h> |
| #include <folly/futures/detail/ThreadWheelTimekeeper.h> |
| #include <chrono> |
| |
| #include <unistd.h> |
| |
| using folly::detail::ThreadWheelTimekeeper; |
| using std::chrono::milliseconds; |
| |
| /* If a callback tries to add a timer, it should not deadlock */ |
| TEST(ThreadWheelTimekeeper, callbackAddsTimer) |
| { |
| ThreadWheelTimekeeper tk; |
| milliseconds now(0); |
| unsigned a = 0; |
| unsigned b = 0; |
| |
| /* If this doesn't complete in 5 seconds... crash */ |
| alarm(5); |
| |
| tk.after(now) |
| .then([&] { |
| a = 1; |
| return tk.after(now) |
| .then([&] { |
| b = 1; |
| }); |
| }) |
| .get(); |
| |
| /* cancel timeout */ |
| alarm(0); |
| |
| EXPECT_EQ(1, a); |
| EXPECT_EQ(1, b); |
| } |