proxygen
FlowTest.cpp File Reference

Go to the source code of this file.

Classes

class  ImmediateFlowSingleSender
 
class  ConcurrentFlowSingleSender
 

Macros

#define MAKE(x)   make_##x
 

Typedefs

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

Functions

 TEST_F (ImmediateFlowSingleSender, EarlyCancellation)
 
 TEST_F (ImmediateFlowSingleSender, LateCancellation)
 
auto make_time (mi::time_source<> &t, NT &ex)
 
 TEST_F (ConcurrentFlowSingleSender, EarlySharedCancellation)
 
 TEST_F (ConcurrentFlowSingleSender, LateSharedCancellation)
 
 TEST_F (ConcurrentFlowSingleSender, RacingSharedCancellation)
 
 TEST_F (ConcurrentFlowSingleSender, EarlyEntangledCancellation)
 
 TEST_F (ConcurrentFlowSingleSender, LateEntangledCancellation)
 
 TEST_F (ConcurrentFlowSingleSender, RacingEntangledCancellation)
 

Macro Definition Documentation

Typedef Documentation

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

Definition at line 124 of file FlowTest.cpp.

Function Documentation

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

Definition at line 126 of file FlowTest.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_F ( ImmediateFlowSingleSender  ,
EarlyCancellation   
)

Definition at line 105 of file FlowTest.cpp.

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

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

Definition at line 115 of file FlowTest.cpp.

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

115  {
116  make_producer() | op::submit(make_consumer([](auto) {
117  // do not stop producer before it is scheduled to run
118  }));
119 
120  EXPECT_THAT(signals_, Eq(110))
121  << "expected that the starting and out.value signals are each recorded once";
122 }
internal::EqMatcher< T > Eq(T x)
#define EXPECT_THAT(value, matcher)
TEST_F ( ConcurrentFlowSingleSender  ,
EarlySharedCancellation   
)

Definition at line 246 of file FlowTest.cpp.

References testing::Eq(), EXPECT_THAT, join, folly::pushmi::shared_entangle(), and stop().

246  {
247  cancellation_test(at_ - 50ms, [](auto& stop, auto& set_stop) {
248  return mi::shared_entangle(stop, set_stop);
249  });
250 
251  join();
252 
253  EXPECT_THAT(signals_, Eq(10011));
254 }
internal::EqMatcher< T > Eq(T x)
auto shared_entangle(First f, Second s) -> shared_entangled_pair< First, Second >
Definition: entangle.h:279
static void stop()
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowSingleSender  ,
LateSharedCancellation   
)

Definition at line 256 of file FlowTest.cpp.

References testing::Eq(), EXPECT_THAT, join, folly::pushmi::shared_entangle(), and stop().

256  {
257  cancellation_test(at_ + 50ms, [](auto& stop, auto& set_stop) {
258  return mi::shared_entangle(stop, set_stop);
259  });
260 
261  join();
262 
263  EXPECT_THAT(signals_, Eq(10111))
264  << "expected that the starting, up.done, out.value and out.done signals are each recorded once";
265 }
internal::EqMatcher< T > Eq(T x)
auto shared_entangle(First f, Second s) -> shared_entangled_pair< First, Second >
Definition: entangle.h:279
static void stop()
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowSingleSender  ,
RacingSharedCancellation   
)

Definition at line 267 of file FlowTest.cpp.

References ASSERT_THAT, testing::Eq(), EXPECT_THAT, join, testing::Lt(), folly::pushmi::shared_entangle(), and stop().

267  {
268  int total = 0;
269  int cancellostrace = 0; // 10111
270  int cancelled = 0; // 10011
271 
272  for (;;) {
273  reset();
274  cancellation_test(at_, [](auto& stop, auto& set_stop) {
275  return mi::shared_entangle(stop, set_stop);
276  });
277 
278  // accumulate known signals
279  ++total;
280  cancellostrace += signals_ == 10111;
281  cancelled += signals_ == 10011;
282 
283  EXPECT_THAT(total, Eq(cancellostrace + cancelled))
284  << signals_ << " <- this set of signals is unrecognized";
285 
286  ASSERT_THAT(total, Lt(100))
287  // too long, show the signals distribution
288  << "total " << total << ", cancel-lost-race " << cancellostrace
289  << ", cancelled " << cancelled;
290 
291  if (cancellostrace > 4 && cancelled > 4) {
292  // yay all known outcomes were observed!
293  break;
294  }
295  // try again
296  continue;
297  }
298 
299  join();
300 }
internal::EqMatcher< T > Eq(T x)
auto shared_entangle(First f, Second s) -> shared_entangled_pair< First, Second >
Definition: entangle.h:279
internal::LtMatcher< Rhs > Lt(Rhs x)
static void stop()
#define EXPECT_THAT(value, matcher)
#define ASSERT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowSingleSender  ,
EarlyEntangledCancellation   
)

Definition at line 302 of file FlowTest.cpp.

References folly::pushmi::entangle(), testing::Eq(), EXPECT_THAT, join, and stop().

302  {
303  cancellation_test(at_ - 50ms, [](auto& stop, auto& set_stop) {
304  return mi::entangle(stop, set_stop);
305  });
306 
307  join();
308 
309  EXPECT_THAT(signals_, Eq(10011));
310 }
internal::EqMatcher< T > Eq(T x)
static void stop()
auto entangle(First f, Second s) -> entangled_pair< First, Second >
Definition: entangle.h:219
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowSingleSender  ,
LateEntangledCancellation   
)

Definition at line 312 of file FlowTest.cpp.

References folly::pushmi::entangle(), testing::Eq(), EXPECT_THAT, join, and stop().

312  {
313  cancellation_test(at_ + 50ms, [](auto& stop, auto& set_stop) {
314  return mi::entangle(stop, set_stop);
315  });
316 
317  join();
318 
319  EXPECT_THAT(signals_, Eq(10111))
320  << "expected that the starting, up.done, out.value and out.done signals are each recorded once";
321 }
internal::EqMatcher< T > Eq(T x)
static void stop()
auto entangle(First f, Second s) -> entangled_pair< First, Second >
Definition: entangle.h:219
#define EXPECT_THAT(value, matcher)
#define join
TEST_F ( ConcurrentFlowSingleSender  ,
RacingEntangledCancellation   
)

Definition at line 323 of file FlowTest.cpp.

References ASSERT_THAT, folly::pushmi::entangle(), testing::Eq(), EXPECT_THAT, join, testing::Lt(), and stop().

323  {
324  int total = 0;
325  int cancellostrace = 0; // 10111
326  int cancelled = 0; // 10011
327 
328  for (;;) {
329  reset();
330  cancellation_test(at_, [](auto& stop, auto& set_stop) {
331  return mi::entangle(stop, set_stop);
332  });
333 
334  // accumulate known signals
335  ++total;
336  cancellostrace += signals_ == 10111;
337  cancelled += signals_ == 10011;
338 
339  EXPECT_THAT(total, Eq(cancellostrace + cancelled))
340  << signals_ << " <- this set of signals is unrecognized";
341 
342  ASSERT_THAT(total, Lt(100))
343  // too long, show the signals distribution
344  << "total " << total << ", cancel-lost-race " << cancellostrace
345  << ", cancelled " << cancelled;
346 
347  if (cancellostrace > 4 && cancelled > 4) {
348  // yay all known outcomes were observed!
349  break;
350  }
351  // try again
352  continue;
353  }
354 
355  join();
356 }
internal::EqMatcher< T > Eq(T x)
internal::LtMatcher< Rhs > Lt(Rhs x)
static void stop()
auto entangle(First f, Second s) -> entangled_pair< First, Second >
Definition: entangle.h:219
#define EXPECT_THAT(value, matcher)
#define ASSERT_THAT(value, matcher)
#define join