proxygen
FlowManyTest.cpp File Reference

Go to the source code of this file.

Classes

class  ImmediateFlowManySender
 
class  ConcurrentFlowManySender
 

Macros

#define MAKE(x)   make_##x
 

Typedefs

using NT = decltype(mi::new_thread())
 

Functions

 TEST_F (ImmediateFlowManySender, EarlyCancellation)
 
 TEST_F (ImmediateFlowManySender, LateCancellation)
 
auto make_time (mi::time_source<> &t, NT &ex)
 
 TEST_F (ConcurrentFlowManySender, EarlyCancellation)
 
 TEST_F (ConcurrentFlowManySender, LateCancellation)
 
 TEST_F (ConcurrentFlowManySender, RacingCancellation)
 
 TEST (FlowManySender, From)
 

Macro Definition Documentation

Typedef Documentation

using NT = decltype(mi::new_thread())

Definition at line 124 of file FlowManyTest.cpp.

Function Documentation

auto make_time ( mi::time_source<> &  t,
NT ex 
)
inline

Definition at line 126 of file FlowManyTest.cpp.

References folly::pushmi::time_source< E, TP >::make().

126  {
127  return t.make(mi::systemNowF{}, [ex]() { return ex; })();
128 }
requires Invocable< ExecutorFactory & > &&Executor< invoke_result_t< ExecutorFactory & > > &&NeverBlocking< invoke_result_t< ExecutorFactory & > > auto make(NF nf, ExecutorFactory ef)
Definition: time_source.h:545
TEST ( FlowManySender  ,
From   
)

Definition at line 293 of file FlowManyTest.cpp.

References testing::Eq(), EXPECT_THAT, f, folly::pushmi::operators::flow_from, for_each(), and MAKE.

293  {
294  auto v = std::array<int, 5>{0, 1, 2, 3, 4};
295  auto f = op::flow_from(v);
296 
297  int actual = 0;
298  f | op::for_each(mi::MAKE(receiver)([&](int) { ++actual; }));
299 
300  EXPECT_THAT(actual, Eq(5)) << "expexcted that all the values are sent once";
301 }
auto f
internal::EqMatcher< T > Eq(T x)
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::operators::flow_from_fn flow_from
#define MAKE(x)
#define EXPECT_THAT(value, matcher)
void for_each(T const &range, Function< void(typename T::value_type const &) const > const &func)
TEST_F ( ImmediateFlowManySender  ,
EarlyCancellation   
)

Definition at line 104 of file FlowManyTest.cpp.

References testing::Eq(), EXPECT_THAT, folly::pushmi::set_done, and submit.

104  {
105  make_producer() | op::submit(make_consumer([](auto up) {
106  // immediately stop producer
107  ::mi::set_done(up);
108  }));
109 
110  EXPECT_THAT(signals_, Eq(10011))
111  << "expected that the starting, up.done and out.done signals are each recorded once";
112 }
internal::EqMatcher< T > Eq(T x)
#define EXPECT_THAT(value, matcher)
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done
TEST_F ( ImmediateFlowManySender  ,
LateCancellation   
)

Definition at line 114 of file FlowManyTest.cpp.

References testing::Eq(), EXPECT_THAT, folly::pushmi::set_value, and submit.

114  {
115  make_producer() | op::submit(make_consumer([](auto up) {
116  // do not stop producer before it is scheduled to run
117  ::mi::set_value(up, 1);
118  }));
119 
120  EXPECT_THAT(signals_, Eq(1000111))
121  << "expected that the starting, up.value, value and done signals are each recorded once";
122 }
internal::EqMatcher< T > Eq(T x)
#define EXPECT_THAT(value, matcher)
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
TEST_F ( ConcurrentFlowManySender  ,
EarlyCancellation   
)

Definition at line 240 of file FlowManyTest.cpp.

References testing::Eq(), EXPECT_THAT, and join.

240  {
241  // this nightmare brought to you by ASAN stack-use-after-return.
242  cancellation_test(at_ - 50ms);
243 
244  join();
245 
246  EXPECT_THAT(signals_, Eq(1010011))
247  << "expected that the starting, up.done and out.done signals are each recorded once";
248 }
internal::EqMatcher< T > Eq(T x)
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowManySender  ,
LateCancellation   
)

Definition at line 250 of file FlowManyTest.cpp.

References testing::Eq(), EXPECT_THAT, and join.

250  {
251  // this nightmare brought to you by ASAN stack-use-after-return.
252  cancellation_test(at_ + 50ms);
253 
254  join();
255 
256  EXPECT_THAT(signals_, Eq(1010111))
257  << "expected that the starting, up.done and out.value signals are each recorded once";
258 }
internal::EqMatcher< T > Eq(T x)
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowManySender  ,
RacingCancellation   
)

Definition at line 260 of file FlowManyTest.cpp.

References ASSERT_THAT, testing::Eq(), EXPECT_THAT, join, and testing::Lt().

260  {
261  int total = 0;
262  int cancellostrace = 0; // 1010111
263  int cancelled = 0; // 1010011
264 
265  for (;;) {
266  reset();
267  cancellation_test(at_);
268 
269  // accumulate known signals
270  ++total;
271  cancellostrace += signals_ == 1010111;
272  cancelled += signals_ == 1010011;
273 
274  EXPECT_THAT(total, Eq(cancellostrace + cancelled))
275  << signals_ << " <- this set of signals is unrecognized";
276 
277  ASSERT_THAT(total, Lt(100))
278  // too long, abort and show the signals distribution
279  << "total " << total << ", cancel-lost-race " << cancellostrace
280  << ", cancelled " << cancelled;
281 
282  if (cancellostrace > 4 && cancelled > 4) {
283  // yay all known outcomes were observed!
284  break;
285  }
286  // try again
287  continue;
288  }
289 
290  join();
291 }
internal::EqMatcher< T > Eq(T x)
internal::LtMatcher< Rhs > Lt(Rhs x)
#define EXPECT_THAT(value, matcher)
#define ASSERT_THAT(value, matcher)
#define join