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