proxygen
FiberIOExecutorTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST_F (FiberIOExecutorTest, event_base)
 
 TEST_F (FiberIOExecutorTest, basic_execution)
 

Function Documentation

TEST_F ( FiberIOExecutorTest  ,
event_base   
)

Definition at line 29 of file FiberIOExecutorTest.cpp.

References ASSERT_EQ, and ASSERT_NE.

29  {
30  auto tpe = std::make_shared<folly::IOThreadPoolExecutor>(1);
32 
33  ASSERT_NE(e.getEventBase(), nullptr);
34  ASSERT_EQ(e.getEventBase(), tpe->getEventBase());
35 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
An IOExecutor that executes funcs under mapped fiber context.
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
TEST_F ( FiberIOExecutorTest  ,
basic_execution   
)

Definition at line 37 of file FiberIOExecutorTest.cpp.

References ASSERT_TRUE, folly::EventBaseManager::get(), folly::fibers::EventBaseLoopController::getEventBase(), folly::VirtualEventBase::getEventBase(), folly::EventBaseManager::getEventBase(), folly::fibers::getFiberManager(), folly::fibers::onFiber(), folly::Baton< MayBlock, Atom >::post(), and folly::Baton< MayBlock, Atom >::wait().

37  {
38  auto tpe = std::make_shared<folly::IOThreadPoolExecutor>(1);
40 
41  // FiberIOExecutor should add tasks using the FiberManager mapped to the
42  // IOThreadPoolExecutor's event base.
43  folly::Baton<> baton;
44  bool inContext = false;
45 
46  e.add([&]() {
47  inContext = folly::fibers::onFiber();
48  auto& lc = dynamic_cast<folly::fibers::EventBaseLoopController&>(
49  folly::fibers::getFiberManager(*e.getEventBase()).loopController());
50  auto& eb = lc.getEventBase()->getEventBase();
51  inContext =
52  inContext && &eb == folly::EventBaseManager::get()->getEventBase();
53  baton.post();
54  });
55  baton.wait();
56 
57  ASSERT_TRUE(inContext);
58 }
EventBase * getEventBase() const
An IOExecutor that executes funcs under mapped fiber context.
static EventBaseManager * get()
FOLLY_ALWAYS_INLINE void wait(const WaitOptions &opt=wait_options()) noexcept
Definition: Baton.h:170
void post() noexcept
Definition: Baton.h:123
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
FiberManager & getFiberManager(EventBase &evb, const FiberManager::Options &opts)