19 #if FOLLY_HAS_COROUTINES 29 using namespace folly;
37 auto future = task42().scheduleOn(&executor).start();
47 TEST(Coro, BasicFuture) {
50 auto future = task42().scheduleOn(&executor).start();
58 (void)co_await task42();
64 auto future = taskVoid().scheduleOn(&executor).start();
73 TEST(Coro, TaskOfMoveOnly) {
75 co_return std::make_unique<int>(123);
92 auto task = taskSleep().scheduleOn(evbThread.
getEventBase());
101 chrono::round<std::chrono::seconds>(totalTime), std::chrono::seconds{1});
105 throw std::runtime_error(
"Test exception");
111 auto future = taskException().scheduleOn(&executor).start();
121 TEST(Coro, FutureThrow) {
123 auto future = taskException().scheduleOn(&executor).start();
135 EXPECT_EQ(depth - 1, co_await taskRecursion(depth - 1));
143 TEST(Coro, LargeStack) {
145 auto task = taskRecursion(5000).scheduleOn(evbThread.
getEventBase());
150 #if defined(__clang__) 151 #define FOLLY_CORO_DONT_OPTIMISE_ON_CLANG __attribute__((optnone)) 153 #define FOLLY_CORO_DONT_OPTIMISE_ON_CLANG 157 EXPECT_EQ(threadId, std::this_thread::get_id());
159 EXPECT_EQ(threadId, std::this_thread::get_id());
164 auto threadId = std::this_thread::get_id();
176 EXPECT_EQ(threadId, std::this_thread::get_id());
181 TEST(Coro, NestedThreads) {
183 auto task = taskThread().scheduleOn(evbThread.
getEventBase());
190 co_return co_await task42().scheduleOn(currentExecutor);
193 TEST(Coro, CurrentExecutor) {
195 auto task = taskGetCurrentExecutor(evbThread.
getEventBase())
206 std::move(fastFuture), std::chrono::milliseconds{100});
210 struct ExpectedException :
public std::runtime_error {
211 ExpectedException() :
std::runtime_error(
"ExpectedException") {}
214 auto throwingFuture =
216 throw ExpectedException();
220 std::move(throwingFuture), std::chrono::milliseconds{100}),
228 std::move(slowFuture), std::chrono::milliseconds{100});
234 TEST(Coro, TimedWait) {
236 taskTimedWait().scheduleOn(&executor).start().via(&executor).getVia(
241 struct AwaitableInt {
242 bool await_ready()
const {
246 bool await_suspend(std::experimental::coroutine_handle<>) {
247 LOG(
FATAL) <<
"Should never be called.";
255 struct AwaitableWithOperator {};
257 AwaitableInt<42>
operator co_await(
const AwaitableWithOperator&) {
262 co_return co_await AwaitableWithOperator();
265 TEST(Coro, AwaitableWithOperator) {
269 taskAwaitableWithOperator()
270 .scheduleOn(&executor)
276 struct AwaitableWithMemberOperator {
277 AwaitableInt<42>
operator co_await() {
282 AwaitableInt<24>
operator co_await(
const AwaitableWithMemberOperator&) {
287 co_return co_await AwaitableWithMemberOperator();
290 TEST(Coro, AwaitableWithMemberOperator) {
294 taskAwaitableWithMemberOperator()
295 .scheduleOn(&executor)
309 auto future = taskBaton(baton).scheduleOn(&executor).start();
324 template <
class Type>
326 co_return co_await folly::makeFuture<Type>(
std::move(value));
329 TEST(Coro, FulfilledFuture) {
332 taskFuture(42).scheduleOn(&executor).start().via(&executor).getVia(
337 TEST(Coro, MoveOnlyReturn) {
339 auto value = taskFuture(std::make_unique<int>(42))
340 .scheduleOn(&executor)
EventBase * getEventBase() const
#define EXPECT_THROW(statement, expected_exception)
#define EXPECT_EQ(val1, val2)
Future< Unit > sleep(Duration dur, Timekeeper *tk)
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
TimedWaitAwaitable< std::decay_t< Awaitable > > timed_wait(Awaitable &&awaitable, std::chrono::milliseconds duration)
#define EXPECT_GE(val1, val2)
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void drive() override
Implements DrivableExecutor.
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
std::thread::id getThreadId() const
#define EXPECT_TRUE(condition)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
auto via(Executor *x, Func &&func) -> Future< typename isFutureOrSemiFuture< decltype(std::declval< Func >()())>::Inner >
#define EXPECT_FALSE(condition)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
auto blockingWait(Awaitable &&awaitable) -> detail::decay_rvalue_reference_t< await_result_t< Awaitable >>