proxygen
TrampolineTest.cpp File Reference

Go to the source code of this file.

Classes

struct  countdownsingle
 
class  TrampolineExecutor
 

Typedefs

using TR = decltype(mi::trampoline())
 

Functions

 TEST_F (TrampolineExecutor, TransformAndSubmit)
 
 TEST_F (TrampolineExecutor, BlockingGet)
 
 TEST_F (TrampolineExecutor, VirtualDerecursion)
 
 TEST_F (TrampolineExecutor, StaticDerecursion)
 
 TEST_F (TrampolineExecutor, UsedWithOn)
 
 TEST_F (TrampolineExecutor, UsedWithVia)
 

Typedef Documentation

using TR = decltype(mi::trampoline())

Definition at line 57 of file TrampolineTest.cpp.

Function Documentation

TEST_F ( TrampolineExecutor  ,
TransformAndSubmit   
)

Definition at line 64 of file TrampolineTest.cpp.

References testing::Eq(), EXPECT_THAT, folly::pushmi::__adl::noexcept(), submit, and folly::pushmi::operators::transform.

64  {
65  auto signals = 0;
66  tr_ | op::transform([](auto) { return 42; }) |
67  op::submit(
68  [&](auto) { signals += 100; },
69  [&](auto) noexcept { signals += 1000; },
70  [&]() { signals += 10; });
71 
72  EXPECT_THAT(signals, Eq(110))
73  << "expected that the value and done signals are each recorded once";
74 }
internal::EqMatcher< T > Eq(T x)
requires E e noexcept(noexcept(s.error(std::move(e))))
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
#define EXPECT_THAT(value, matcher)
TEST_F ( TrampolineExecutor  ,
BlockingGet   
)

Definition at line 76 of file TrampolineTest.cpp.

References testing::Eq(), EXPECT_THAT, and folly::pushmi::operators::transform.

76  {
77  auto v = tr_ | op::transform([](auto) { return 42; }) | op::get<int>;
78 
79  EXPECT_THAT(v, Eq(42)) << "expected that the result would be different";
80 }
internal::EqMatcher< T > Eq(T x)
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
#define EXPECT_THAT(value, matcher)
TEST_F ( TrampolineExecutor  ,
VirtualDerecursion   
)

Definition at line 82 of file TrampolineTest.cpp.

References counter.

82  {
83  int counter = 100'000;
84  std::function<void(::folly::pushmi::any_executor_ref<> exec)> recurse;
85  recurse = [&](::folly::pushmi::any_executor_ref<> tr) {
86  if (--counter <= 0)
87  return;
88  tr | op::submit(recurse);
89  };
90  tr_ | op::submit([&](auto exec) { recurse(exec); });
91 
92  EXPECT_THAT(counter, Eq(0))
93  << "expected that all nested submissions complete";
94 }
std::atomic< int > counter
TEST_F ( TrampolineExecutor  ,
StaticDerecursion   
)

Definition at line 96 of file TrampolineTest.cpp.

References testing::Eq(), EXPECT_THAT, single, and submit.

96  {
97  int counter = 100'000;
98  countdownsingle single{counter};
99  tr_ | op::submit(single);
100 
101  EXPECT_THAT(counter, Eq(0))
102  << "expected that all nested submissions complete";
103 }
std::atomic< int > counter
TEST_F ( TrampolineExecutor  ,
UsedWithOn   
)

Definition at line 105 of file TrampolineTest.cpp.

References testing::ElementsAre(), testing::Eq(), EXPECT_THAT, folly::pushmi::inline_executor(), folly::pushmi::make_single_sender, max, min, folly::pushmi::operators::on, folly::pushmi::on_value(), folly::pushmi::set_done, folly::pushmi::set_value, submit, value, and values().

105  {
106  std::vector<std::string> values;
107  auto sender = ::folly::pushmi::make_single_sender([](auto out) {
108  ::folly::pushmi::set_value(out, 2.0);
110  // ignored
114  });
115  auto inlineon = sender | op::on([&]() { return mi::inline_executor(); });
116  inlineon | op::submit(v::on_value([&](auto v) {
117  values.push_back(folly::to<std::string>(v));
118  }));
119 
120  EXPECT_THAT(values, ElementsAre(folly::to<std::string>(2.0)))
121  << "expected that only the first item was pushed";
122 
123  EXPECT_THAT(
124  (std::is_same<
125  mi::executor_t<decltype(sender)>,
126  mi::executor_t<decltype(inlineon)>>::value),
127  Eq(true))
128  << "expected that executor was not changed by on";
129 }
auto on_value(Fns...fns) -> on_value_fn< Fns... >
Definition: boosters.h:262
LogLevel max
Definition: LogLevel.cpp:31
internal::EqMatcher< T > Eq(T x)
LogLevel min
Definition: LogLevel.cpp:30
static const char *const value
Definition: Conv.cpp:50
#define EXPECT_THAT(value, matcher)
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
inline_executor_t inline_executor()
Definition: inline.h:113
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
PUSHMI_INLINE_VAR constexpr detail::on_fn on
Definition: on.h:100
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_single_sender_fn make_single_sender
std::vector< int > values(1'000)
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done
TEST_F ( TrampolineExecutor  ,
UsedWithVia   
)

Definition at line 131 of file TrampolineTest.cpp.

References testing::ElementsAre(), testing::Eq(), EXPECT_THAT, folly::pushmi::inline_executor(), folly::pushmi::make_single_sender, max, min, folly::pushmi::on_value(), folly::pushmi::set_done, folly::pushmi::set_value, submit, value, values(), and folly::pushmi::operators::via.

131  {
132  std::vector<std::string> values;
133  auto sender = ::folly::pushmi::make_single_sender([](auto out) {
134  ::folly::pushmi::set_value(out, 2.0);
136  // ignored
140  });
141  auto inlinevia = sender | op::via([&]() { return mi::inline_executor(); });
142  inlinevia | op::submit(v::on_value([&](auto v) {
143  values.push_back(folly::to<std::string>(v));
144  }));
145 
146  EXPECT_THAT(values, ElementsAre(folly::to<std::string>(2.0)))
147  << "expected that only the first item was pushed";
148 
149  EXPECT_THAT(
150  (!std::is_same<
151  mi::executor_t<decltype(sender)>,
152  mi::executor_t<decltype(inlinevia)>>::value),
153  Eq(true))
154  << "expected that executor was changed by via";
155 }
auto on_value(Fns...fns) -> on_value_fn< Fns... >
Definition: boosters.h:262
LogLevel max
Definition: LogLevel.cpp:31
internal::EqMatcher< T > Eq(T x)
PUSHMI_INLINE_VAR constexpr detail::via_fn via
Definition: via.h:166
LogLevel min
Definition: LogLevel.cpp:30
static const char *const value
Definition: Conv.cpp:50
#define EXPECT_THAT(value, matcher)
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
inline_executor_t inline_executor()
Definition: inline.h:113
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_single_sender_fn make_single_sender
std::vector< int > values(1'000)
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done