blob: 8e9f70b51f3474fe1312720b674c393490fa4f09 [file] [log] [blame]
#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);
}