proxygen
AsyncSocketHandlerTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (AsyncSocketHandlerTest, WriteErrOnShutdown)
 
 TEST (AsyncSocketHandlerTest, TransportActiveInactive)
 

Function Documentation

TEST ( AsyncSocketHandlerTest  ,
WriteErrOnShutdown   
)

Definition at line 27 of file AsyncSocketHandlerTest.cpp.

References testing::_, dummy(), EXPECT_CALL, folly::AsyncSocket::newSocket(), and folly::netops::socket().

27  {
29 
30  EventBase evb;
31  auto socket = AsyncSocket::newSocket(&evb);
33  auto pipeline = DefaultPipeline::create();
34  pipeline->setPipelineManager(&manager);
35  pipeline->addBack(AsyncSocketHandler(socket)).finalize();
36 
37  // close() the pipeline multiple times.
38  // deletePipeline should only be called once.
39  EXPECT_CALL(manager, deletePipeline(_)).Times(1);
40  pipeline->close();
41  pipeline->close();
42 }
void dummy()
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST ( AsyncSocketHandlerTest  ,
TransportActiveInactive   
)

Definition at line 44 of file AsyncSocketHandlerTest.cpp.

References testing::_, dummy(), EXPECT_CALL, handler(), folly::AsyncSocket::newSocket(), testing::Return(), and folly::netops::socket().

44  {
46 
47  EventBase evb;
48  auto socket = AsyncSocket::newSocket(&evb);
49  auto handler = std::make_shared<StrictMock<MockBytesToBytesHandler>>();
50  auto pipeline = DefaultPipeline::create();
51  pipeline->addBack(AsyncSocketHandler(socket));
52  pipeline->addBack(handler);
53  pipeline->finalize();
54 
55  EXPECT_CALL(*handler, transportActive(_)).Times(1);
56  pipeline->transportActive();
57  EXPECT_CALL(*handler, transportInactive(_)).Times(1);
58  pipeline->transportInactive();
59  EXPECT_CALL(*handler, transportActive(_)).Times(1);
60  pipeline->transportActive();
61  // Transport is currently active. Calling pipeline->close()
62  // should result in transportInactive being fired.
63  EXPECT_CALL(*handler, mockClose(_))
64  .WillOnce(Return(handler->defaultFuture()));
65  EXPECT_CALL(*handler, transportInactive(_)).Times(1);
66  pipeline->close();
67 
68  socket = AsyncSocket::newSocket(&evb);
69  handler = std::make_shared<StrictMock<MockBytesToBytesHandler>>();
70  pipeline = DefaultPipeline::create();
71  pipeline->addBack(AsyncSocketHandler(socket));
72  pipeline->addBack(handler);
73  pipeline->finalize();
74 
75  EXPECT_CALL(*handler, transportActive(_)).Times(1);
76  pipeline->transportActive();
77  EXPECT_CALL(*handler, transportInactive(_)).Times(1);
78  pipeline->transportInactive();
79  // Transport is currently inactive. Calling pipeline->close()
80  // should not result in transportInactive being fired.
81  EXPECT_CALL(*handler, mockClose(_))
82  .WillOnce(Return(handler->defaultFuture()));
83  EXPECT_CALL(*handler, transportInactive(_)).Times(0);
84  pipeline->close();
85 }
void handler(int, siginfo_t *, void *)
void dummy()
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)