proxygen
FutureDAGTest.cpp File Reference
#include <folly/experimental/FutureDAG.h>
#include <boost/thread/barrier.hpp>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

struct  FutureDAGTest
 
struct  FutureDAGTest::TestNode
 

Functions

 TEST_F (FutureDAGTest, SingleNode)
 
 TEST_F (FutureDAGTest, RemoveSingleNode)
 
 TEST_F (FutureDAGTest, RemoveNodeComplex)
 
 TEST_F (FutureDAGTest, ResetDAG)
 
 TEST_F (FutureDAGTest, FanOut)
 
 TEST_F (FutureDAGTest, FanIn)
 
 TEST_F (FutureDAGTest, FanOutFanIn)
 
 TEST_F (FutureDAGTest, Complex)
 
 TEST_F (FutureDAGTest, ThrowBegin)
 
 TEST_F (FutureDAGTest, ThrowEnd)
 
 TEST_F (FutureDAGTest, Cycle1)
 
 TEST_F (FutureDAGTest, Cycle2)
 
 TEST_F (FutureDAGTest, Cycle3)
 
 TEST_F (FutureDAGTest, DestroyBeforeComplete)
 

Variables

FutureDAG::FutureFunc makeFutureFunc = [] { return makeFuture(); }
 
FutureDAG::FutureFunc throwFunc
 

Function Documentation

TEST_F ( FutureDAGTest  ,
SingleNode   
)

Definition at line 101 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

101  {
102  add();
103  ASSERT_NO_THROW(dag->go().get());
104  checkOrder();
105 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
RemoveSingleNode   
)

Definition at line 107 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

107  {
108  auto h1 = add();
109  auto h2 = add();
110  (void)h1;
111  remove(h2);
112  ASSERT_NO_THROW(dag->go().get());
113  checkOrder();
114 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
RemoveNodeComplex   
)

Definition at line 116 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

116  {
117  auto h1 = add();
118  auto h2 = add();
119  auto h3 = add();
120  dependency(h1, h3);
121  dependency(h2, h1);
122  remove(h3);
123  remove(h2);
124  remove(h1);
125  ASSERT_NO_THROW(dag->go().get());
126  checkOrder();
127 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
ResetDAG   
)

Definition at line 129 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

129  {
130  auto h1 = add();
131  auto h2 = add();
132  auto h3 = add();
133  dependency(h3, h1);
134  dependency(h2, h3);
135 
136  reset();
137  ASSERT_NO_THROW(dag->go().get());
138  checkOrder();
139 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
FanOut   
)

Definition at line 141 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

141  {
142  auto h1 = add();
143  auto h2 = add();
144  auto h3 = add();
145  dependency(h1, h2);
146  dependency(h1, h3);
147  ASSERT_NO_THROW(dag->go().get());
148  checkOrder();
149 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
FanIn   
)

Definition at line 151 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

151  {
152  auto h1 = add();
153  auto h2 = add();
154  auto h3 = add();
155  dependency(h1, h3);
156  dependency(h2, h3);
157  ASSERT_NO_THROW(dag->go().get());
158  checkOrder();
159 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
FanOutFanIn   
)

Definition at line 161 of file FutureDAGTest.cpp.

References add, and ASSERT_NO_THROW.

161  {
162  auto h1 = add();
163  auto h2 = add();
164  auto h3 = add();
165  auto h4 = add();
166  dependency(h1, h3);
167  dependency(h1, h2);
168  dependency(h2, h4);
169  dependency(h3, h4);
170  ASSERT_NO_THROW(dag->go().get());
171  checkOrder();
172 }
auto add
Definition: BaseTest.cpp:70
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
Complex   
)

Definition at line 174 of file FutureDAGTest.cpp.

References add, ASSERT_NO_THROW, C, D, and M.

174  {
175  auto A = add();
176  auto B = add();
177  auto C = add();
178  auto D = add();
179  auto E = add();
180  auto F = add();
181  auto G = add();
182  auto H = add();
183  auto I = add();
184  auto J = add();
185  auto K = add();
186  auto L = add();
187  auto M = add();
188  auto N = add();
189 
190  dependency(A, B);
191  dependency(A, C);
192  dependency(A, D);
193  dependency(A, J);
194  dependency(C, H);
195  dependency(D, E);
196  dependency(E, F);
197  dependency(E, G);
198  dependency(F, H);
199  dependency(G, H);
200  dependency(H, I);
201  dependency(J, K);
202  dependency(K, L);
203  dependency(K, M);
204  dependency(L, N);
205  dependency(I, N);
206 
207  ASSERT_NO_THROW(dag->go().get());
208  checkOrder();
209 }
std::unique_ptr< int > A
auto add
Definition: BaseTest.cpp:70
#define D(name, bit)
Definition: CpuId.h:145
#define C(name, bit)
Definition: CpuId.h:204
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
Definition: Hazptr.h:104
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851
TEST_F ( FutureDAGTest  ,
ThrowBegin   
)

Definition at line 217 of file FutureDAGTest.cpp.

References EXPECT_THROW, makeFutureFunc, and throwFunc.

217  {
218  auto h1 = dag->add(throwFunc);
219  auto h2 = dag->add(makeFutureFunc);
220  dag->dependency(h1, h2);
221  EXPECT_THROW(dag->go().get(), std::runtime_error);
222 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
FutureDAG::FutureFunc throwFunc
FutureDAG::FutureFunc makeFutureFunc
TEST_F ( FutureDAGTest  ,
ThrowEnd   
)

Definition at line 224 of file FutureDAGTest.cpp.

References EXPECT_THROW, makeFutureFunc, and throwFunc.

224  {
225  auto h1 = dag->add(makeFutureFunc);
226  auto h2 = dag->add(throwFunc);
227  dag->dependency(h1, h2);
228  EXPECT_THROW(dag->go().get(), std::runtime_error);
229 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
FutureDAG::FutureFunc throwFunc
FutureDAG::FutureFunc makeFutureFunc
TEST_F ( FutureDAGTest  ,
Cycle1   
)

Definition at line 231 of file FutureDAGTest.cpp.

References add, and EXPECT_THROW.

231  {
232  auto h1 = add();
233  dependency(h1, h1);
234  EXPECT_THROW(dag->go().get(), std::runtime_error);
235 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
auto add
Definition: BaseTest.cpp:70
TEST_F ( FutureDAGTest  ,
Cycle2   
)

Definition at line 237 of file FutureDAGTest.cpp.

References add, and EXPECT_THROW.

237  {
238  auto h1 = add();
239  auto h2 = add();
240  dependency(h1, h2);
241  dependency(h2, h1);
242  EXPECT_THROW(dag->go().get(), std::runtime_error);
243 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
auto add
Definition: BaseTest.cpp:70
TEST_F ( FutureDAGTest  ,
Cycle3   
)

Definition at line 245 of file FutureDAGTest.cpp.

References add, and EXPECT_THROW.

245  {
246  auto h1 = add();
247  auto h2 = add();
248  auto h3 = add();
249  dependency(h1, h2);
250  dependency(h2, h3);
251  dependency(h3, h1);
252  EXPECT_THROW(dag->go().get(), std::runtime_error);
253 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
auto add
Definition: BaseTest.cpp:70
TEST_F ( FutureDAGTest  ,
DestroyBeforeComplete   
)

Definition at line 255 of file FutureDAGTest.cpp.

References ASSERT_NO_THROW, folly::FutureDAG::create(), f, makeFutureFunc, folly::gen::move, and folly::pushmi::detail::t.

255  {
256  auto barrier = std::make_shared<boost::barrier>(2);
257  Future<Unit> f;
258  {
259  auto localDag = FutureDAG::create();
260  auto h1 = localDag->add([barrier] {
261  auto p = std::make_shared<Promise<Unit>>();
262  std::thread t([p, barrier] {
263  barrier->wait();
264  p->setValue();
265  });
266  t.detach();
267  return p->getFuture();
268  });
269  auto h2 = localDag->add(makeFutureFunc);
270  localDag->dependency(h1, h2);
271  f = localDag->go();
272  }
273  barrier->wait();
274  ASSERT_NO_THROW(std::move(f).get());
275 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FutureDAG::FutureFunc makeFutureFunc
#define ASSERT_NO_THROW(statement)
Definition: gtest.h:1851

Variable Documentation

FutureDAG::FutureFunc makeFutureFunc = [] { return makeFuture(); }

Definition at line 211 of file FutureDAGTest.cpp.

Referenced by TEST_F().

Initial value:
= [] {
return makeFuture<Unit>(std::runtime_error("oops"));
}

Definition at line 213 of file FutureDAGTest.cpp.

Referenced by TEST_F().