Commit 26276668 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Drain TimedDrivableExecutor on destruction to correctly clean up future chains.

Summary: In future chains destruction of the future then the promise will cause an exception to propagate. If all the work builds up in the executor and the executor does not drain then the exception does not propagate.

Reviewed By: yfeldblum

Differential Revision: D6837229

fbshipit-source-id: 095650b8aae0de4ddbe86c044d78a6fac45f9c46
parent 2e6097a3
......@@ -29,6 +29,12 @@ namespace folly {
*/
class TimedDrivableExecutor : public DrivableExecutor {
public:
~TimedDrivableExecutor() noexcept {
// Drain on destruction so that if work is added here during the collapse
// of a future train, it will propagate.
drain();
}
/// Implements DrivableExecutor
void drive() noexcept override;
......
......@@ -23,8 +23,8 @@
using namespace folly;
TEST(TimedDrivableExecutor, runIsStable) {
TimedDrivableExecutor x;
size_t count = 0;
TimedDrivableExecutor x;
auto f1 = [&]() { count++; };
auto f2 = [&]() {
x.add(f1);
......@@ -36,8 +36,8 @@ TEST(TimedDrivableExecutor, runIsStable) {
}
TEST(TimedDrivableExecutor, drainIsNotStable) {
TimedDrivableExecutor x;
size_t count = 0;
TimedDrivableExecutor x;
auto f1 = [&]() { count++; };
auto f2 = [&]() {
x.add(f1);
......@@ -49,8 +49,8 @@ TEST(TimedDrivableExecutor, drainIsNotStable) {
}
TEST(TimedDrivableExecutor, try_drive) {
TimedDrivableExecutor x;
size_t count = 0;
TimedDrivableExecutor x;
auto f1 = [&]() { count++; };
x.try_drive();
EXPECT_EQ(count, 0);
......@@ -60,8 +60,8 @@ TEST(TimedDrivableExecutor, try_drive) {
}
TEST(TimedDrivableExecutor, try_drive_for) {
TimedDrivableExecutor x;
size_t count = 0;
TimedDrivableExecutor x;
auto f1 = [&]() { count++; };
x.try_drive_for(std::chrono::milliseconds(100));
EXPECT_EQ(count, 0);
......@@ -71,8 +71,8 @@ TEST(TimedDrivableExecutor, try_drive_for) {
}
TEST(TimedDrivableExecutor, try_drive_until) {
TimedDrivableExecutor x;
size_t count = 0;
TimedDrivableExecutor x;
auto f1 = [&]() { count++; };
x.try_drive_until(
std::chrono::system_clock::now() + std::chrono::milliseconds(100));
......
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