proxygen
AsyncSocketIntegrationTest Class Reference
Inheritance diagram for AsyncSocketIntegrationTest:
testing::Test

Public Member Functions

void SetUp () override
 
void startServer ()
 
void TearDown () override
 
std::unique_ptr< UDPClientperformPingPongTest (folly::Optional< folly::SocketAddress > connectedAddress, bool useConnectedWrite)
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Public Attributes

folly::EventBase sevb
 
folly::EventBase cevb
 
std::unique_ptr< std::thread > serverThread
 
std::unique_ptr< UDPServerserver
 
std::unique_ptr< UDPClientclient
 

Additional Inherited Members

- Public Types inherited from testing::Test
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc
 
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc
 
- Static Public Member Functions inherited from testing::Test
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
static void SetUpTestCase ()
 
static void TearDownTestCase ()
 
static bool HasFatalFailure ()
 
static bool HasNonfatalFailure ()
 
static bool HasFailure ()
 
static void RecordProperty (const std::string &key, const std::string &value)
 
static void RecordProperty (const std::string &key, int value)
 
- Protected Member Functions inherited from testing::Test
 Test ()
 
 Test ()
 
 Test ()
 

Detailed Description

Definition at line 325 of file AsyncUDPSocketTest.cpp.

Member Function Documentation

std::unique_ptr< UDPClient > AsyncSocketIntegrationTest::performPingPongTest ( folly::Optional< folly::SocketAddress connectedAddress,
bool  useConnectedWrite 
)

Definition at line 367 of file AsyncUDPSocketTest.cpp.

References folly::Optional< Value >::hasValue(), and folly::gen::move.

369  {
370  if (useConnectedWrite) {
371  CHECK(connectedAddress.hasValue());
372  client = std::make_unique<ConnectedWriteUDPClient>(&cevb);
373  client->setShouldConnect(*connectedAddress);
374  } else {
375  client = std::make_unique<UDPClient>(&cevb);
376  if (connectedAddress) {
377  client->setShouldConnect(*connectedAddress);
378  }
379  }
380  // Start event loop in a separate thread
381  auto clientThread = std::thread([this]() { cevb.loopForever(); });
382 
383  // Wait for event loop to start
385 
386  // Send ping
387  cevb.runInEventBaseThread([&]() { client->start(server->address(), 100); });
388 
389  // Wait for client to finish
390  clientThread.join();
391  return std::move(client);
392 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< UDPServer > server
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
void waitUntilRunning()
Definition: EventBase.cpp:249
std::unique_ptr< UDPClient > client
void AsyncSocketIntegrationTest::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 327 of file AsyncUDPSocketTest.cpp.

327  {
328  server = std::make_unique<UDPServer>(
329  &sevb, folly::SocketAddress("127.0.0.1", 0), 4);
330 
331  // Start event loop in a separate thread
332  serverThread =
333  std::make_unique<std::thread>([this]() { sevb.loopForever(); });
334 
335  // Wait for event loop to start
336  sevb.waitUntilRunning();
337  }
std::unique_ptr< UDPServer > server
std::unique_ptr< std::thread > serverThread
void AsyncSocketIntegrationTest::startServer ( )
inline

Definition at line 339 of file AsyncUDPSocketTest.cpp.

339  {
340  // Start the server
341  sevb.runInEventBaseThreadAndWait([&]() { server->start(); });
342  LOG(INFO) << "Server listening=" << server->address();
343  }
bool runInEventBaseThreadAndWait(void(*fn)(T *), T *arg)
Definition: EventBase.h:799
std::unique_ptr< UDPServer > server
void AsyncSocketIntegrationTest::TearDown ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 345 of file AsyncUDPSocketTest.cpp.

345  {
346  // Shutdown server
347  sevb.runInEventBaseThread([&]() {
348  server->shutdown();
350  });
351 
352  // Wait for server thread to join
353  serverThread->join();
354  }
std::unique_ptr< UDPServer > server
void terminateLoopSoon()
Definition: EventBase.cpp:493
bool runInEventBaseThread(void(*fn)(T *), T *arg)
Definition: EventBase.h:794
std::unique_ptr< std::thread > serverThread

Member Data Documentation

folly::EventBase AsyncSocketIntegrationTest::cevb

Definition at line 361 of file AsyncUDPSocketTest.cpp.

std::unique_ptr<UDPClient> AsyncSocketIntegrationTest::client

Definition at line 364 of file AsyncUDPSocketTest.cpp.

std::unique_ptr<UDPServer> AsyncSocketIntegrationTest::server

Definition at line 363 of file AsyncUDPSocketTest.cpp.

std::unique_ptr<std::thread> AsyncSocketIntegrationTest::serverThread

Definition at line 362 of file AsyncUDPSocketTest.cpp.

folly::EventBase AsyncSocketIntegrationTest::sevb

Definition at line 360 of file AsyncUDPSocketTest.cpp.


The documentation for this class was generated from the following file: