proxygen
ThreadedExecutorTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST_F (ThreadedExecutorTest, example)
 
 TEST_F (ThreadedExecutorTest, dtor_waits)
 
 TEST_F (ThreadedExecutorTest, many)
 
 TEST_F (ThreadedExecutorTest, many_sleeping_constant_time)
 
 TEST_F (ThreadedExecutorTest, many_sleeping_decreasing_time)
 

Function Documentation

TEST_F ( ThreadedExecutorTest  ,
example   
)

Definition at line 29 of file ThreadedExecutorTest.cpp.

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

29  {
31  auto ret = folly::via(&x)
32  .thenValue([&](auto&&) { return 42; })
33  .thenValue([&](int n) { return folly::to<std::string>(n); })
34  .get();
35 
36  EXPECT_EQ("42", ret);
37 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
TEST_F ( ThreadedExecutorTest  ,
dtor_waits   
)

Definition at line 39 of file ThreadedExecutorTest.cpp.

References EXPECT_TRUE, and folly::via().

39  {
40  constexpr auto kDelay = std::chrono::milliseconds(100);
41  auto x = std::make_unique<folly::ThreadedExecutor>();
42  auto fut = folly::via(&*x, [&] { /* sleep override */
43  std::this_thread::sleep_for(kDelay);
44  });
45  x = nullptr;
46 
47  EXPECT_TRUE(fut.isReady());
48 }
Definition: InvokeTest.cpp:58
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
TEST_F ( ThreadedExecutorTest  ,
many   
)

Definition at line 50 of file ThreadedExecutorTest.cpp.

References folly::collect(), EXPECT_EQ, i, k, folly::gen::map(), folly::via(), and x.

50  {
51  constexpr auto kNumTasks = 1024;
53  auto rets =
55  folly::gen::range<size_t>(0, kNumTasks) |
56  folly::gen::map([&](size_t i) {
57  return folly::via(&x)
58  .thenValue([=](auto&&) { return i; })
59  .thenValue([](size_t k) { return folly::to<std::string>(k); });
60  }) |
61  folly::gen::as<std::vector>())
62  .get();
63 
64  EXPECT_EQ("42", rets[42]);
65 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Map map(Predicate pred=Predicate())
Definition: Base.h:545
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
Definition: Future-inl.h:1536
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
KeyT k
TEST_F ( ThreadedExecutorTest  ,
many_sleeping_constant_time   
)

Definition at line 67 of file ThreadedExecutorTest.cpp.

References folly::collect(), EXPECT_EQ, i, k, folly::gen::map(), folly::via(), and x.

67  {
68  constexpr auto kNumTasks = 256;
69  constexpr auto kDelay = std::chrono::milliseconds(100);
71  auto rets =
73  folly::gen::range<size_t>(0, kNumTasks) |
74  folly::gen::map([&](size_t i) {
75  return folly::via(&x)
76  .thenValue([=](auto&&) {
77  /* sleep override */ std::this_thread::sleep_for(kDelay);
78  })
79  .thenValue([=](auto&&) { return i; })
80  .thenValue([](size_t k) { return folly::to<std::string>(k); });
81  }) |
82  folly::gen::as<std::vector>())
83  .get();
84 
85  EXPECT_EQ("42", rets[42]);
86 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Map map(Predicate pred=Predicate())
Definition: Base.h:545
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
Definition: Future-inl.h:1536
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
KeyT k
TEST_F ( ThreadedExecutorTest  ,
many_sleeping_decreasing_time   
)

Definition at line 88 of file ThreadedExecutorTest.cpp.

References folly::collect(), EXPECT_EQ, i, k, folly::gen::map(), folly::via(), and x.

88  {
89  constexpr auto kNumTasks = 256;
90  constexpr auto kDelay = std::chrono::milliseconds(100);
92  auto rets =
94  folly::gen::range<size_t>(0, kNumTasks) |
95  folly::gen::map([&](size_t i) {
96  return folly::via(&x)
97  .thenValue([=](auto&&) {
98  auto delay = kDelay * (kNumTasks - i) / kNumTasks;
99  /* sleep override */ std::this_thread::sleep_for(delay);
100  })
101  .thenValue([=](auto&&) { return i; })
102  .thenValue([](size_t k) { return folly::to<std::string>(k); });
103  }) |
104  folly::gen::as<std::vector>())
105  .get();
106 
107  EXPECT_EQ("42", rets[42]);
108 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
Map map(Predicate pred=Predicate())
Definition: Base.h:545
Future< std::vector< typename std::iterator_traits< InputIterator >::value_type::value_type > > collect(InputIterator first, InputIterator last)
Definition: Future-inl.h:1536
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
Definition: Future-inl.h:1290
KeyT k