(Wangle) Re-add race test
authorHannes Roth <hannesr@fb.com>
Wed, 10 Jun 2015 16:06:50 +0000 (09:06 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 10 Jun 2015 21:37:23 +0000 (14:37 -0700)
Summary: I figured this test would be useless since it tests a check added before
everything was converted to FSM. But since it appears to fail on Mac OS
X, it might be useful to have after all.

Reviewed By: @fugalh

Differential Revision: D2143500

folly/futures/test/ViaTest.cpp

index 9acac1bc86edb62be1af06aa231f11ee01d08bd3..72b2e1e86f636ac67b143ae72d1b2faf91743840 100644 (file)
@@ -414,3 +414,30 @@ TEST(Via, viaRaces) {
   t1.join();
   t2.join();
 }
+
+TEST(Future, callbackRace) {
+  ThreadExecutor x;
+
+  auto fn = [&x]{
+    auto promises = std::make_shared<std::vector<Promise<void>>>(4);
+    std::vector<Future<void>> futures;
+
+    for (auto& p : *promises) {
+      futures.emplace_back(
+        p.getFuture()
+        .via(&x)
+        .then([](Try<void>&&){}));
+    }
+
+    x.waitForStartup();
+    x.add([promises]{
+      for (auto& p : *promises) {
+        p.setValue();
+      }
+    });
+
+    return collectAll(futures);
+  };
+
+  fn().wait();
+}