proxygen
EventBaseThreadTest.cpp File Reference

Go to the source code of this file.

Classes

class  EventBaseThreadTest
 

Functions

 TEST_F (EventBaseThreadTest, example)
 
 TEST_F (EventBaseThreadTest, start_stop)
 
 TEST_F (EventBaseThreadTest, move)
 
 TEST_F (EventBaseThreadTest, self_move)
 
 TEST_F (EventBaseThreadTest, default_manager)
 
 TEST_F (EventBaseThreadTest, custom_manager)
 

Function Documentation

TEST_F ( EventBaseThreadTest  ,
example   
)

Definition at line 32 of file EventBaseThreadTest.cpp.

References ASSERT_TRUE, EXPECT_EQ, folly::getCurrentThreadName(), folly::EventBaseThread::getEventBase(), folly::Baton< MayBlock, Atom >::post(), folly::EventBase::runInEventBaseThread(), folly::Baton< MayBlock, Atom >::try_wait_for(), and value.

32  {
33  EventBaseThread ebt(true, nullptr, "monkey");
34 
35  Baton<> done;
36  ebt.getEventBase()->runInEventBaseThread([&] {
37  EXPECT_EQ(getCurrentThreadName().value(), "monkey");
38  done.post();
39  });
40  ASSERT_TRUE(done.try_wait_for(seconds(1)));
41 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_ALWAYS_INLINE bool try_wait_for(const std::chrono::duration< Rep, Period > &timeout, const WaitOptions &opt=wait_options()) noexcept
Definition: Baton.h:206
static const char *const value
Definition: Conv.cpp:50
void post() noexcept
Definition: Baton.h:123
Optional< std::string > getCurrentThreadName()
Definition: ThreadName.cpp:105
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( EventBaseThreadTest  ,
start_stop   
)

Definition at line 43 of file EventBaseThreadTest.cpp.

References ASSERT_TRUE, EXPECT_EQ, EXPECT_NE, folly::EventBaseThread::getEventBase(), i, folly::EventBase::runInEventBaseThread(), folly::EventBaseThread::start(), and folly::EventBaseThread::stop().

43  {
44  EventBaseThread ebt(false);
45 
46  for (size_t i = 0; i < 4; ++i) {
47  EXPECT_EQ(nullptr, ebt.getEventBase());
48  ebt.start();
49  EXPECT_NE(nullptr, ebt.getEventBase());
50 
51  Baton<> done;
52  ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
53  ASSERT_TRUE(done.try_wait_for(seconds(1)));
54 
55  EXPECT_NE(nullptr, ebt.getEventBase());
56  ebt.stop();
57  EXPECT_EQ(nullptr, ebt.getEventBase());
58  }
59 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( EventBaseThreadTest  ,
move   
)

Definition at line 61 of file EventBaseThreadTest.cpp.

References ASSERT_TRUE, EXPECT_EQ, EXPECT_NE, and folly::gen::move.

61  {
62  auto ebt0 = EventBaseThread();
63  auto ebt1 = std::move(ebt0);
64  auto ebt2 = std::move(ebt1);
65 
66  EXPECT_EQ(nullptr, ebt0.getEventBase());
67  EXPECT_EQ(nullptr, ebt1.getEventBase());
68  EXPECT_NE(nullptr, ebt2.getEventBase());
69 
70  Baton<> done;
71  ebt2.getEventBase()->runInEventBaseThread([&] { done.post(); });
72  ASSERT_TRUE(done.try_wait_for(seconds(1)));
73 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( EventBaseThreadTest  ,
self_move   
)

Definition at line 75 of file EventBaseThreadTest.cpp.

References ASSERT_TRUE, EXPECT_NE, and folly::gen::move.

75  {
76  EventBaseThread ebt0;
77  auto ebt = std::move(ebt0);
78 
79  EXPECT_NE(nullptr, ebt.getEventBase());
80 
81  Baton<> done;
82  ebt.getEventBase()->runInEventBaseThread([&] { done.post(); });
83  ASSERT_TRUE(done.try_wait_for(seconds(1)));
84 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( EventBaseThreadTest  ,
default_manager   
)

Definition at line 86 of file EventBaseThreadTest.cpp.

References EXPECT_EQ, folly::pushmi::operators::get, folly::EventBaseThread::getEventBase(), and folly::EventBase::runInEventBaseThreadAndWait().

86  {
87  auto ebm = EventBaseManager::get();
88  EventBaseThread ebt;
89  auto ebt_eb = ebt.getEventBase();
90  auto ebm_eb = static_cast<EventBase*>(nullptr);
91  ebt_eb->runInEventBaseThreadAndWait([&] { ebm_eb = ebm->getEventBase(); });
92  EXPECT_EQ(uintptr_t(ebt_eb), uintptr_t(ebm_eb));
93 }
bool runInEventBaseThreadAndWait(void(*fn)(T *), T *arg)
Definition: EventBase.h:799
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
EventBase * getEventBase() const
PUSHMI_INLINE_VAR constexpr detail::get_fn< T > get
Definition: submit.h:391
TEST_F ( EventBaseThreadTest  ,
custom_manager   
)

Definition at line 95 of file EventBaseThreadTest.cpp.

References EXPECT_EQ, folly::EventBaseThread::getEventBase(), folly::EventBaseManager::getEventBase(), and folly::EventBase::runInEventBaseThreadAndWait().

95  {
96  EventBaseManager ebm;
97  EventBaseThread ebt(&ebm);
98  auto ebt_eb = ebt.getEventBase();
99  auto ebm_eb = static_cast<EventBase*>(nullptr);
100  ebt_eb->runInEventBaseThreadAndWait([&] { ebm_eb = ebm.getEventBase(); });
101  EXPECT_EQ(uintptr_t(ebt_eb), uintptr_t(ebm_eb));
102 }
EventBase * getEventBase() const
bool runInEventBaseThreadAndWait(void(*fn)(T *), T *arg)
Definition: EventBase.h:799
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922