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; {
ExecutorTester tester; Promise<Unit> p;
auto f = p.getFuture() ExecutorTester tester;
.via(&tester) auto f = p.getFuture()
.within(milliseconds(100)) .via(&tester)
.thenValue([&](auto&&) {}); .within(std::chrono::seconds(10))
p.setValue(); .thenValue([&](auto&&) {});
f.wait(); p.setValue();
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) // 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