31 using namespace folly;
39 original_.getEventBase()->runInEventBaseThreadAndWait([=] {
40 originalThreadId_ = std::this_thread::get_id();
41 auto evb = original_.getEventBase();
46 sockPtr_.reset(sslSock);
49 alternate_.getEventBase()->runInEventBaseThreadAndWait(
50 [=] { alternateThreadId_ = std::this_thread::get_id(); });
56 alternate_.getEventBase());
61 evbHelper_->destroy();
84 .WillOnce(
Invoke([&](
auto sock,
auto nextProtocol,
auto&&,
auto&&) {
85 EXPECT_EQ(original_.getEventBase(), sock->getEventBase());
86 EXPECT_EQ(originalThreadId_, std::this_thread::get_id());
93 .WillOnce(
Invoke([&](
auto sock,
auto cb) {
94 EXPECT_EQ(alternate_.getEventBase(), sock->getEventBase());
95 EXPECT_EQ(alternateThreadId_, std::this_thread::get_id());
97 sock->getEventBase()->runInLoop([sock, cb] {
101 SecureTransportType::TLS,
106 original_.getEventBase()->runInEventBaseThreadAndWait(
107 [=] { evbHelper_->start(
std::move(sockPtr_), &mockCb_); });
110 FAIL() <<
"Timeout waiting for connectionReady callback to be called";
117 EXPECT_NE(
nullptr, sockPtr_->getEventBase());
119 .WillOnce(
Invoke([&](
auto sock,
auto&&,
auto&&) {
121 EXPECT_EQ(originalThreadId_, std::this_thread::get_id());
126 .WillOnce(
Invoke([&](
auto sock,
auto cb) {
127 EXPECT_EQ(alternate_.getEventBase(), sock->getEventBase());
128 EXPECT_EQ(alternateThreadId_, std::this_thread::get_id());
130 sock->getEventBase()->runInLoop([sock, cb,
this] {
135 EXPECT_EQ(alternate_.getEventBase(), sock->getEventBase());
140 original_.getEventBase()->runInEventBaseThreadAndWait(
141 [=] { evbHelper_->start(
std::move(sockPtr_), &mockCb_); });
144 FAIL() <<
"Timeout while waiting for connectionError callback to be called";
152 EXPECT_EQ(alternateThreadId_, std::this_thread::get_id());
155 alternate_.getEventBase()->runInEventBaseThreadAndWait([=]{
156 evbHelper_->connectionError(sslSock_, {}, {});
163 .WillOnce(SaveArg<0>(&transport));
166 .WillOnce(
Invoke([&](
auto sock,
auto&&) {
167 EXPECT_EQ(alternate_.getEventBase(), sock->getEventBase());
168 EXPECT_EQ(alternateThreadId_, std::this_thread::get_id());
170 sockPtr_.reset(sslSock_);
174 original_.getEventBase()->runInEventBaseThreadAndWait(
175 [=] { evbHelper_->start(
std::move(sockPtr_), &mockCb_); });
178 FAIL() <<
"Timeout while waiting for startInternal to be called";
183 original_.getEventBase()->runInEventBaseThreadAndWait(
184 [=] { evbHelper_->dropConnection(SSLErrorEnum::DROPPED); });
187 FAIL() <<
"Timeout while waiting for dropConnection to be called";
204 .WillOnce(
Invoke([&](
auto,
auto,
auto) {
212 .WillOnce(
Invoke([&](
auto,
auto,
auto,
auto) {
219 .WillOnce(
Invoke([&](
auto sock,
auto&&) {
220 EXPECT_EQ(alternate_.getEventBase(), sock->getEventBase());
221 EXPECT_EQ(alternateThreadId_, std::this_thread::get_id());
223 sockPtr_.reset(sslSock_);
227 original_.getEventBase()->runInEventBaseThreadAndWait(
228 [=] { evbHelper_->start(
std::move(sockPtr_), &mockCb_); });
231 FAIL() <<
"Timeout while waiting for startInternal to be called";
237 original_.getEventBase()->runInEventBaseThread([=, &raceBarrier] {
238 raceBarrier.
wait().get();
239 evbHelper_->dropConnection(SSLErrorEnum::DROPPED);
242 alternate_.getEventBase()->runInEventBaseThread(
243 [=, &raceBarrier, &connectionReadyCalled]()
mutable {
244 raceBarrier.
wait().get();
245 evbHelper_->connectionReady(
std::move(sockPtr_),
"test", {}, {});
246 connectionReadyCalled.
post();
252 FAIL() <<
"Timeout while waiting for connectionError to be called";
256 FAIL() <<
"Timeout while waiting for connectionReady to call";
ScopedEventBaseThread original_
folly::Future< bool > wait()
GTEST_API_ Cardinality AtMost(int n)
MockHandshakeHelperCallback< UseOwnedRawPtrPolicy > mockCb_
TEST_F(EvbHandshakeHelperTest, TestSuccessPath)
std::atomic< std::thread::id > alternateThreadId_
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
std::atomic< std::thread::id > originalThreadId_
—— Concurrent Priority Queue Implementation ——
FOLLY_ALWAYS_INLINE bool try_wait_for(const std::chrono::duration< Rep, Period > &timeout, const WaitOptions &opt=wait_options()) noexcept
std::unique_ptr< AsyncSSLSocket, Destructor > UniquePtr
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_TRUE(condition)
#define EXPECT_NE(val1, val2)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
std::unique_ptr< AcceptorHandshakeHelper, folly::DelayedDestruction::Destructor > UniquePtr
ScopedEventBaseThread alternate_