Commit f07bb93a authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Fix Timekeeper.executor test

Summary:
1. Patch the test to remove racy behavior
2. Added another test for a case where the timeout is hit.

Reviewed By: yfeldblum

Differential Revision: D25854609

fbshipit-source-id: c1694e5b46b9645dc3e71a12ddc8ed12e8cf270c
parent 12bcb6a9
......@@ -426,23 +426,39 @@ TEST(Timekeeper, semiFutureWithinChainedInterruptTest) {
TEST(Timekeeper, executor) {
class ExecutorTester : public DefaultKeepAliveExecutor {
public:
~ExecutorTester() override { joinKeepAlive(); }
virtual void add(Func f) override {
count++;
f();
}
void join() { joinKeepAlive(); }
std::atomic<int> count{0};
};
{
Promise<Unit> p;
ExecutorTester tester;
auto f = p.getFuture()
.via(&tester)
.within(milliseconds(100))
.within(std::chrono::seconds(10))
.thenValue([&](auto&&) {});
p.setValue();
f.wait();
EXPECT_EQ(2, tester.count);
std::move(f).get();
tester.join();
EXPECT_EQ(3, tester.count);
}
{
Promise<Unit> p;
ExecutorTester tester;
auto f = p.getFuture()
.via(&tester)
.within(std::chrono::milliseconds(10))
.thenValue([&](auto&&) {});
EXPECT_THROW(std::move(f).get(), FutureTimeout);
p.setValue();
tester.join();
EXPECT_EQ(3, tester.count);
}
}
// TODO(5921764)
......
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