proxygen
ViaTest.cpp File Reference

Go to the source code of this file.

Classes

struct  ManualWaiter
 
struct  ViaFixture
 
struct  PriorityExecutor
 
class  ThreadExecutor
 Simple executor that does work in another thread. More...
 
class  DummyDrivableExecutor
 

Functions

 TEST (Via, exceptionOnLaunch)
 
 TEST (Via, thenValue)
 
 TEST (Via, thenFuture)
 
static Future< std::stringdoWorkStatic (Try< std::string > &&t)
 
 TEST (Via, thenFunction)
 
 TEST_F (ViaFixture, threadHops)
 
 TEST_F (ViaFixture, chainVias)
 
 TEST_F (ViaFixture, bareViaAssignment)
 
 TEST_F (ViaFixture, viaAssignment)
 
 TEST (Via, chain1)
 
 TEST (Via, chain3)
 
 TEST (Via, priority)
 
 TEST_F (ViaFixture, chainX1)
 
 TEST_F (ViaFixture, chainX3)
 
 TEST (Via, then2)
 
 TEST (Via, then2Variadic)
 
 TEST (Via, viaThenGetWasRacy)
 
 TEST (Via, callbackRace)
 
 TEST (Via, getVia)
 
 TEST (Via, SimpleTimedGetVia)
 
 TEST (Via, getTryVia)
 
 TEST (Via, SimpleTimedGetTryVia)
 
 TEST (Via, waitVia)
 
 TEST (Via, viaRaces)
 
 TEST (Via, viaDummyExecutorFutureSetValueFirst)
 
 TEST (Via, viaDummyExecutorFutureSetCallbackFirst)
 
 TEST (Via, viaExecutorDiscardsTaskFutureSetValueFirst)
 
 TEST (Via, viaExecutorDiscardsTaskFutureSetCallbackFirst)
 
 TEST (ViaFunc, liftsVoid)
 
 TEST (ViaFunc, value)
 
 TEST (ViaFunc, exception)
 
 TEST (ViaFunc, future)
 
 TEST (ViaFunc, semi_future)
 
 TEST (ViaFunc, voidFuture)
 
 TEST (ViaFunc, isSticky)
 
 TEST (ViaFunc, moveOnly)
 
 TEST (ViaFunc, valueKeepAlive)
 
 TEST (ViaFunc, thenValueKeepAlive)
 

Function Documentation

static Future<std::string> doWorkStatic ( Try< std::string > &&  t)
static

Definition at line 95 of file ViaTest.cpp.

References folly::makeFuture(), and folly::pushmi::detail::t.

Referenced by TEST().

95  {
96  return makeFuture(t.value() + ";static");
97 }
T & value()&
Definition: Try-inl.h:140
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
exceptionOnLaunch   
)

Definition at line 76 of file ViaTest.cpp.

References EXPECT_THROW.

76  {
77  auto future = makeFuture<int>(std::runtime_error("E"));
78  EXPECT_THROW(future.value(), std::runtime_error);
79 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
TEST ( Via  ,
thenValue   
)

Definition at line 81 of file ViaTest.cpp.

References EXPECT_TRUE, folly::makeFuture(), folly::gen::move, and folly::pushmi::detail::t.

81  {
82  auto future = makeFuture(std::move(1)).then([](Try<int>&& t) {
83  return t.value() == 1;
84  });
85 
86  EXPECT_TRUE(future.value());
87 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Definition: Try.h:51
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
thenFuture   
)

Definition at line 89 of file ViaTest.cpp.

References EXPECT_TRUE, folly::makeFuture(), and folly::pushmi::detail::t.

89  {
90  auto future = makeFuture(1).then(
91  [](Try<int>&& t) { return makeFuture(t.value() == 1); });
92  EXPECT_TRUE(future.value());
93 }
Definition: Try.h:51
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
thenFunction   
)

Definition at line 99 of file ViaTest.cpp.

References doWork(), doWorkStatic(), EXPECT_EQ, f, folly::makeFuture(), string, and folly::pushmi::detail::t.

99  {
100  struct Worker {
102  return makeFuture(t.value() + ";class");
103  }
105  return makeFuture(t.value() + ";class-static");
106  }
107  } w;
108 
109  auto f = makeFuture(std::string("start"))
110  .then(doWorkStatic)
111  .then(Worker::doWorkStatic)
112  .then(&Worker::doWork, &w);
113 
114  EXPECT_EQ(f.value(), "start;static;class-static;class");
115 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void doWork(int work)
static Future< std::string > doWorkStatic(Try< std::string > &&t)
Definition: ViaTest.cpp:95
Definition: Try.h:51
const char * string
Definition: Conv.cpp:212
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
chain1   
)

Definition at line 174 of file ViaTest.cpp.

References EXPECT_EQ, and folly::makeFuture().

174  {
175  EXPECT_EQ(42, makeFuture().thenMulti([] { return 42; }).get());
176 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
chain3   
)

Definition at line 178 of file ViaTest.cpp.

References count, EXPECT_EQ, f, folly::makeFuture(), folly::gen::move, and string.

178  {
179  int count = 0;
180  auto f = makeFuture().thenMulti(
181  [&] {
182  count++;
183  return 3.14159;
184  },
185  [&](double) {
186  count++;
187  return std::string("hello");
188  },
189  [&] {
190  count++;
191  return makeFuture(42);
192  });
193  EXPECT_EQ(42, std::move(f).get());
194  EXPECT_EQ(3, count);
195 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
int * count
const char * string
Definition: Conv.cpp:212
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
priority   
)

Definition at line 225 of file ViaTest.cpp.

References PriorityExecutor::count0, PriorityExecutor::count1, PriorityExecutor::count2, exe, EXPECT_EQ, folly::Executor::HI_PRI, folly::Executor::LO_PRI, and folly::via().

225  {
227  via(&exe, -1).thenValue([](auto&&) {});
228  via(&exe, 0).thenValue([](auto&&) {});
229  via(&exe, 1).thenValue([](auto&&) {});
230  via(&exe, 42).thenValue([](auto&&) {}); // overflow should go to max priority
231  via(&exe, -42).thenValue(
232  [](auto&&) {}); // underflow should go to min priority
233  via(&exe).thenValue([](auto&&) {}); // default to mid priority
234  via(&exe, Executor::LO_PRI).thenValue([](auto&&) {});
235  via(&exe, Executor::HI_PRI).thenValue([](auto&&) {});
236  EXPECT_EQ(3, exe.count0);
237  EXPECT_EQ(2, exe.count1);
238  EXPECT_EQ(3, exe.count2);
239 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
InlineExecutor exe
Definition: Benchmark.cpp:337
TEST ( Via  ,
then2   
)

Definition at line 273 of file ViaTest.cpp.

References a, b, c, EXPECT_FALSE, EXPECT_TRUE, folly::ManualExecutor::run(), and folly::via().

273  {
274  ManualExecutor x1, x2;
275  bool a = false, b = false, c = false;
276  via(&x1)
277  .thenValue([&](auto&&) { a = true; })
278  .then(&x2, [&](auto&&) { b = true; })
279  .thenValue([&](auto&&) { c = true; });
280 
281  EXPECT_FALSE(a);
282  EXPECT_FALSE(b);
283 
284  x1.run();
285  EXPECT_TRUE(a);
286  EXPECT_FALSE(b);
287  EXPECT_FALSE(c);
288 
289  x2.run();
290  EXPECT_TRUE(b);
291  EXPECT_FALSE(c);
292 
293  x1.run();
294  EXPECT_TRUE(c);
295 }
char b
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
char a
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST ( Via  ,
then2Variadic   
)

Definition at line 297 of file ViaTest.cpp.

References a, EXPECT_FALSE, EXPECT_TRUE, f, folly::foo, testing::gmock_matchers_test::foo, folly::makeFuture(), folly::ManualExecutor::run(), and x.

297  {
298  struct Foo {
299  bool a = false;
300  void foo(Try<Unit>) {
301  a = true;
302  }
303  };
304  Foo f;
306  makeFuture().then(&x, &Foo::foo, &f);
307  EXPECT_FALSE(f.a);
308  x.run();
309  EXPECT_TRUE(f.a);
310 }
auto f
Foo(std::atomic< int > &d)
const int x
char a
Definition: Try.h:51
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
viaThenGetWasRacy   
)

Definition at line 351 of file ViaTest.cpp.

References ASSERT_TRUE, EXPECT_EQ, val, folly::via(), and x.

351  {
353  std::unique_ptr<int> val =
354  folly::via(&x)
355  .thenValue([](auto&&) { return std::make_unique<int>(42); })
356  .get();
357  ASSERT_TRUE(!!val);
358  EXPECT_EQ(42, *val);
359 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
double val
Definition: String.cpp:273
Simple executor that does work in another thread.
Definition: ViaTest.cpp:314
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( Via  ,
callbackRace   
)

Definition at line 361 of file ViaTest.cpp.

References ThreadExecutor::add(), folly::collectAll(), ThreadExecutor::waitForStartup(), and x.

361  {
363 
364  auto fn = [&x] {
365  auto promises = std::make_shared<std::vector<Promise<Unit>>>(4);
366  std::vector<Future<Unit>> futures;
367 
368  for (auto& p : *promises) {
369  futures.emplace_back(p.getFuture().via(&x).then([](Try<Unit>&&) {}));
370  }
371 
372  x.waitForStartup();
373  x.add([promises] {
374  for (auto& p : *promises) {
375  p.setValue();
376  }
377  });
378 
379  return collectAll(futures);
380  };
381 
382  fn().wait();
383 }
std::vector< typename std::enable_if< !std::is_same< invoke_result_t< typename std::iterator_traits< InputIterator >::value_type >, void >::value, invoke_result_t< typename std::iterator_traits< InputIterator >::value_type > >::type > collectAll(InputIterator first, InputIterator last)
Definition: WhenN-inl.h:147
const int x
Simple executor that does work in another thread.
Definition: ViaTest.cpp:314
Definition: Try.h:51
void waitForStartup()
Definition: ViaTest.cpp:346
void add(Func fn) override
Definition: ViaTest.cpp:342
TEST ( Via  ,
getVia   
)

Definition at line 395 of file ViaTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, f, folly::makeFuture(), DummyDrivableExecutor::ran, folly::via(), and x.

395  {
396  {
397  // non-void
399  auto f = via(&x).thenValue([](auto&&) { return true; });
400  EXPECT_TRUE(f.getVia(&x));
401  }
402 
403  {
404  // void
406  auto f = via(&x).then();
407  f.getVia(&x);
408  }
409 
410  {
412  auto f = makeFuture(true);
413  EXPECT_TRUE(f.getVia(&x));
414  EXPECT_FALSE(x.ran);
415  }
416 }
auto f
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
SimpleTimedGetVia   
)

Definition at line 418 of file ViaTest.cpp.

References EXPECT_THROW, f, and folly::Promise< T >::getFuture().

418  {
421  auto f = p.getFuture();
422  EXPECT_THROW(f.getVia(&e2, std::chrono::seconds(1)), FutureTimeout);
423 }
auto f
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( Via  ,
getTryVia   
)

Definition at line 425 of file ViaTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, f, folly::makeFuture(), DummyDrivableExecutor::ran, folly::pushmi::detail::t, folly::via(), and x.

425  {
426  {
427  // non-void
429  auto f = via(&x).thenValue([](auto&&) { return 23; });
430  EXPECT_FALSE(f.isReady());
431  EXPECT_EQ(23, f.getTryVia(&x).value());
432  }
433 
434  {
435  // void
437  auto f = via(&x).then();
438  EXPECT_FALSE(f.isReady());
439  auto t = f.getTryVia(&x);
440  EXPECT_TRUE(t.hasValue());
441  }
442 
443  {
445  auto f = makeFuture(23);
446  EXPECT_EQ(23, f.getTryVia(&x).value());
447  EXPECT_FALSE(x.ran);
448  }
449 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
SimpleTimedGetTryVia   
)

Definition at line 451 of file ViaTest.cpp.

References EXPECT_THROW, f, and folly::Promise< T >::getFuture().

451  {
454  auto f = p.getFuture();
455  EXPECT_THROW(f.getTryVia(&e2, std::chrono::seconds(1)), FutureTimeout);
456 }
auto f
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
Future< T > getFuture()
Definition: Promise-inl.h:97
TEST ( Via  ,
waitVia   
)

Definition at line 458 of file ViaTest.cpp.

References EXPECT_FALSE, EXPECT_TRUE, f, folly::makeFuture(), DummyDrivableExecutor::ran, folly::via(), and x.

458  {
459  {
461  auto f = via(&x).then();
462  EXPECT_FALSE(f.isReady());
463  f.waitVia(&x);
464  EXPECT_TRUE(f.isReady());
465  }
466 
467  {
468  // try rvalue as well
470  auto f = via(&x).then().waitVia(&x);
471  EXPECT_TRUE(f.isReady());
472  }
473 
474  {
476  makeFuture(true).waitVia(&x);
477  EXPECT_FALSE(x.ran);
478  }
479 }
auto f
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
viaRaces   
)

Definition at line 481 of file ViaTest.cpp.

References EXPECT_EQ, folly::Promise< T >::getFuture(), folly::ManualExecutor::run(), folly::Promise< T >::setValue(), and x.

481  {
483  Promise<Unit> p;
484  auto tid = std::this_thread::get_id();
485  bool done = false;
486 
487  std::thread t1([&] {
488  p.getFuture()
489  .via(&x)
490  .then([&](Try<Unit>&&) { EXPECT_EQ(tid, std::this_thread::get_id()); })
491  .then([&](Try<Unit>&&) { EXPECT_EQ(tid, std::this_thread::get_id()); })
492  .then([&](Try<Unit>&&) { done = true; });
493  });
494 
495  std::thread t2([&] { p.setValue(); });
496 
497  while (!done) {
498  x.run();
499  }
500  t1.join();
501  t2.join();
502 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Future< T > getFuture()
Definition: Promise-inl.h:97
Definition: Try.h:51
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
TEST ( Via  ,
viaDummyExecutorFutureSetValueFirst   
)

Definition at line 504 of file ViaTest.cpp.

References c, EXPECT_THROW, folly::Promise< T >::getFuture(), folly::makeFuture(), folly::gen::move, and x.

504  {
505  // The callback object will get destroyed when passed to the executor.
506 
507  // A promise will be captured by the callback lambda so we can observe that
508  // it will be destroyed.
509  Promise<Unit> captured_promise;
510  auto captured_promise_future = captured_promise.getFuture();
511 
513  auto future = makeFuture().via(&x).thenValue(
514  [c = std::move(captured_promise)](auto&&) { return 42; });
515 
516  EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise);
517  EXPECT_THROW(
518  std::move(captured_promise_future).get(std::chrono::seconds(5)),
519  BrokenPromise);
520 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Future< T > getFuture()
Definition: Promise-inl.h:97
char c
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
viaDummyExecutorFutureSetCallbackFirst   
)

Definition at line 522 of file ViaTest.cpp.

References c, EXPECT_THROW, folly::Promise< T >::getFuture(), folly::gen::move, folly::Promise< T >::setValue(), and x.

522  {
523  // The callback object will get destroyed when passed to the executor.
524 
525  // A promise will be captured by the callback lambda so we can observe that
526  // it will be destroyed.
527  Promise<Unit> captured_promise;
528  auto captured_promise_future = captured_promise.getFuture();
529 
531  Promise<Unit> trigger;
532  auto future = trigger.getFuture().via(&x).thenValue(
533  [c = std::move(captured_promise)](auto&&) { return 42; });
534  trigger.setValue();
535 
536  EXPECT_THROW(std::move(future).get(std::chrono::seconds(5)), BrokenPromise);
537  EXPECT_THROW(
538  std::move(captured_promise_future).get(std::chrono::seconds(5)),
539  BrokenPromise);
540 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Future< T > getFuture()
Definition: Promise-inl.h:97
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
char c
TEST ( Via  ,
viaExecutorDiscardsTaskFutureSetValueFirst   
)

Definition at line 542 of file ViaTest.cpp.

References c, folly::ManualExecutor::clear(), EXPECT_THROW, folly::Promise< T >::getFuture(), folly::makeFuture(), folly::gen::move, and x.

542  {
543  // The callback object will get destroyed when the ManualExecutor runs out
544  // of scope.
545 
546  // A promise will be captured by the callback lambda so we can observe that
547  // it will be destroyed.
548  Promise<Unit> captured_promise;
549  auto captured_promise_future = captured_promise.getFuture();
550 
551  Optional<Future<int>> future;
552  {
554  future = makeFuture().via(&x).thenValue(
555  [c = std::move(captured_promise)](auto&&) { return 42; });
556  x.clear();
557  }
558 
559  EXPECT_THROW(std::move(*future).get(std::chrono::seconds(5)), BrokenPromise);
560  EXPECT_THROW(
561  std::move(captured_promise_future).get(std::chrono::seconds(5)),
562  BrokenPromise);
563 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Future< T > getFuture()
Definition: Promise-inl.h:97
char c
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( Via  ,
viaExecutorDiscardsTaskFutureSetCallbackFirst   
)

Definition at line 565 of file ViaTest.cpp.

References c, folly::ManualExecutor::clear(), EXPECT_THROW, folly::Promise< T >::getFuture(), folly::gen::move, folly::Promise< T >::setValue(), and x.

565  {
566  // The callback object will get destroyed when the ManualExecutor runs out
567  // of scope.
568 
569  // A promise will be captured by the callback lambda so we can observe that
570  // it will be destroyed.
571  Promise<Unit> captured_promise;
572  auto captured_promise_future = captured_promise.getFuture();
573 
574  Optional<Future<int>> future;
575  {
577  Promise<Unit> trigger;
578  future = trigger.getFuture().via(&x).thenValue(
579  [c = std::move(captured_promise)](auto&&) { return 42; });
580  trigger.setValue();
581  x.clear();
582  }
583 
584  EXPECT_THROW(std::move(*future).get(std::chrono::seconds(5)), BrokenPromise);
585  EXPECT_THROW(
586  std::move(captured_promise_future).get(std::chrono::seconds(5)),
587  BrokenPromise);
588 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
Future< T > getFuture()
Definition: Promise-inl.h:97
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
char c
TEST ( ViaFunc  ,
liftsVoid   
)

Definition at line 590 of file ViaTest.cpp.

References count, EXPECT_EQ, f, folly::ManualExecutor::run(), folly::via(), and x.

590  {
592  int count = 0;
593  Future<Unit> f = via(&x, [&] { count++; });
594 
595  EXPECT_EQ(0, count);
596  x.run();
597  EXPECT_EQ(1, count);
598 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
int * count
TEST ( ViaFunc  ,
value   
)

Definition at line 600 of file ViaTest.cpp.

References EXPECT_EQ, folly::via(), and x.

600  {
602  EXPECT_EQ(42, via(&x, [] { return 42; }).getVia(&x));
603 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
TEST ( ViaFunc  ,
exception   
)

Definition at line 605 of file ViaTest.cpp.

References EXPECT_THROW, folly::via(), and x.

605  {
607  EXPECT_THROW(
608  via(&x, []() -> int { throw std::runtime_error("expected"); }).getVia(&x),
609  std::runtime_error);
610 }
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
TEST ( ViaFunc  ,
future   
)

Definition at line 612 of file ViaTest.cpp.

References EXPECT_EQ, folly::makeFuture(), folly::via(), and x.

612  {
614  EXPECT_EQ(42, via(&x, [] { return makeFuture(42); }).getVia(&x));
615 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST ( ViaFunc  ,
semi_future   
)

Definition at line 617 of file ViaTest.cpp.

References EXPECT_EQ, folly::makeSemiFuture(), folly::via(), and x.

617  {
619  EXPECT_EQ(42, via(&x, [] { return makeSemiFuture(42); }).getVia(&x));
620 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
SemiFuture< typename std::decay< T >::type > makeSemiFuture(T &&t)
Definition: Future-inl.h:712
TEST ( ViaFunc  ,
voidFuture   
)

Definition at line 622 of file ViaTest.cpp.

References count, EXPECT_EQ, folly::via(), and x.

622  {
624  int count = 0;
625  via(&x, [&] { count++; }).getVia(&x);
626  EXPECT_EQ(1, count);
627 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
int * count
TEST ( ViaFunc  ,
isSticky   
)

Definition at line 629 of file ViaTest.cpp.

References count, EXPECT_EQ, f, folly::gen::move, folly::ManualExecutor::run(), folly::via(), and x.

629  {
631  int count = 0;
632 
633  auto f = via(&x, [&] { count++; });
634  x.run();
635 
636  std::move(f).thenValue([&](auto&&) { count++; });
637  EXPECT_EQ(1, count);
638  x.run();
639  EXPECT_EQ(2, count);
640 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
int * count
TEST ( ViaFunc  ,
moveOnly   
)

Definition at line 642 of file ViaTest.cpp.

References EXPECT_EQ, folly::gen::move, folly::via(), and x.

642  {
644  auto intp = std::make_unique<int>(42);
645 
646  EXPECT_EQ(42, via(&x, [intp = std::move(intp)] { return *intp; }).getVia(&x));
647 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
TEST ( ViaFunc  ,
valueKeepAlive   
)

Definition at line 649 of file ViaTest.cpp.

References EXPECT_EQ, folly::getKeepAliveToken(), folly::via(), and x.

649  {
651  EXPECT_EQ(42, via(getKeepAliveToken(&x), [] { return 42; }).getVia(&x));
652 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
Executor::KeepAlive< ExecutorT > getKeepAliveToken(ExecutorT *executor)
Definition: Executor.h:200
TEST ( ViaFunc  ,
thenValueKeepAlive   
)

Definition at line 654 of file ViaTest.cpp.

References EXPECT_EQ, folly::getKeepAliveToken(), folly::via(), and x.

654  {
656  EXPECT_EQ(
657  42,
659  .thenValue([](auto&&) { return 42; })
660  .getVia(&x));
661 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
Executor::KeepAlive< ExecutorT > getKeepAliveToken(ExecutorT *executor)
Definition: Executor.h:200
TEST_F ( ViaFixture  ,
threadHops   
)

Definition at line 117 of file ViaTest.cpp.

References EXPECT_EQ, EXPECT_NE, f, folly::pushmi::detail::t, and folly::via().

117  {
118  auto westThreadId = std::this_thread::get_id();
119  auto f = via(eastExecutor.get())
120  .then([=](Try<Unit>&& /* t */) {
121  EXPECT_NE(std::this_thread::get_id(), westThreadId);
122  return makeFuture<int>(1);
123  })
124  .via(westExecutor.get())
125  .then([=](Try<int>&& t) {
126  EXPECT_EQ(std::this_thread::get_id(), westThreadId);
127  return t.value();
128  });
129  EXPECT_EQ(f.getVia(waiter.get()), 1);
130 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
Definition: Try.h:51
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
TEST_F ( ViaFixture  ,
chainVias   
)

Definition at line 132 of file ViaTest.cpp.

References EXPECT_EQ, EXPECT_NE, f, folly::makeFuture(), val, and folly::via().

132  {
133  auto westThreadId = std::this_thread::get_id();
134  auto f = via(eastExecutor.get())
135  .thenValue([=](auto&&) {
136  EXPECT_NE(std::this_thread::get_id(), westThreadId);
137  return 1;
138  })
139  .then([=](int val) {
140  return makeFuture(val)
141  .via(westExecutor.get())
142  .then([=](int v) mutable {
143  EXPECT_EQ(std::this_thread::get_id(), westThreadId);
144  return v + 1;
145  });
146  })
147  .then([=](int val) {
148  // even though ultimately the future that triggers this one
149  // executed in the west thread, this then() inherited the
150  // executor from its predecessor, ie the eastExecutor.
151  EXPECT_NE(std::this_thread::get_id(), westThreadId);
152  return val + 1;
153  })
154  .via(westExecutor.get())
155  .then([=](int val) {
156  // go back to west, so we can wait on it
157  EXPECT_EQ(std::this_thread::get_id(), westThreadId);
158  return val + 1;
159  });
160 
161  EXPECT_EQ(f.getVia(waiter.get()), 4);
162 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
double val
Definition: String.cpp:273
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST_F ( ViaFixture  ,
bareViaAssignment   
)

Definition at line 164 of file ViaTest.cpp.

References f, and folly::via().

164  {
165  auto f = via(eastExecutor.get());
166 }
auto f
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
TEST_F ( ViaFixture  ,
viaAssignment   
)

Definition at line 167 of file ViaTest.cpp.

References f, and folly::makeFuture().

167  {
168  // via()&&
169  auto f = makeFuture().via(eastExecutor.get());
170  // via()&
171  auto f2 = f.via(eastExecutor.get());
172 }
auto f
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST_F ( ViaFixture  ,
chainX1   
)

Definition at line 241 of file ViaTest.cpp.

References EXPECT_EQ, and folly::makeFuture().

241  {
242  EXPECT_EQ(
243  42,
244  makeFuture()
245  .thenMultiWithExecutor(eastExecutor.get(), [] { return 42; })
246  .get());
247 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
TEST_F ( ViaFixture  ,
chainX3   
)

Definition at line 249 of file ViaTest.cpp.

References count, EXPECT_EQ, EXPECT_NE, f, folly::makeFuture(), string, and folly::via().

249  {
250  auto westThreadId = std::this_thread::get_id();
251  int count = 0;
252  auto f = via(westExecutor.get())
253  .thenMultiWithExecutor(
254  eastExecutor.get(),
255  [&] {
256  EXPECT_NE(std::this_thread::get_id(), westThreadId);
257  count++;
258  return 3.14159;
259  },
260  [&](double) {
261  count++;
262  return std::string("hello");
263  },
264  [&] { count++; })
265  .thenValue([&](auto&&) {
266  EXPECT_EQ(std::this_thread::get_id(), westThreadId);
267  return makeFuture(42);
268  });
269  EXPECT_EQ(42, f.getVia(waiter.get()));
270  EXPECT_EQ(3, count);
271 }
auto f
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
int * count
const char * string
Definition: Conv.cpp:212
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310