fix future executor test
[folly.git] / folly / experimental / wangle / concurrent / test / ThreadPoolExecutorTest.cpp
index 00d5ccac2588106f28efee2d5bca71cf74bb3282..e3336615484ef1aa636f2a562995fbf7fda8163a 100644 (file)
@@ -249,7 +249,8 @@ static void futureExecutor() {
       EXPECT_THROW(t.value(), std::runtime_error);
     });
   // Test doing actual async work
-  fe.addFuture([] () {
+  folly::Baton<> baton;
+  fe.addFuture([&] () {
     auto p = std::make_shared<Promise<int>>();
     std::thread t([p](){
       burnMs(10)();
@@ -260,8 +261,9 @@ static void futureExecutor() {
   }).then([&] (Try<int>&& t) {
     EXPECT_EQ(42, t.value());
     c++;
+    baton.post();
   });
-  burnMs(15)(); // Sleep long enough for the promise to be fulfilled
+  baton.wait();
   fe.join();
   EXPECT_EQ(6, c);
 }