From: Hannes Roth <hannesr@fb.com>
Date: Wed, 10 Jun 2015 16:06:50 +0000 (-0700)
Subject: (Wangle) Re-add race test
X-Git-Tag: v0.47.0~50
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bf590e16a063840e2691f775da187be04cb7bd2f;p=folly.git

(Wangle) Re-add race test

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
---

diff --git a/folly/futures/test/ViaTest.cpp b/folly/futures/test/ViaTest.cpp
index 9acac1bc..72b2e1e8 100644
--- a/folly/futures/test/ViaTest.cpp
+++ b/folly/futures/test/ViaTest.cpp
@@ -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();
+}