fix future executor test
authorJames Sedgwick <jsedgwick@fb.com>
Fri, 26 Sep 2014 19:17:01 +0000 (12:17 -0700)
committerAnton Likhtarov <alikhtarov@fb.com>
Fri, 26 Sep 2014 22:28:17 +0000 (15:28 -0700)
Summary: This should be the last test abusing sleeps.

Test Plan: ran

Reviewed By: hannesr@fb.com

Subscribers: fugalh, njormrod

FB internal diff: D1580830

Tasks: 5225808

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);
 }