proxygen
AsyncSocketHandlerTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gtest/gtest.h>
22 
23 using namespace folly;
24 using namespace testing;
25 using namespace wangle;
26 
27 TEST(AsyncSocketHandlerTest, WriteErrOnShutdown) {
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 }
43 
44 TEST(AsyncSocketHandlerTest, TransportActiveInactive) {
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 
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 }
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void handler(int, siginfo_t *, void *)
void dummy()
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
Definition: AsyncSocket.h:281
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST(SequencedExecutor, CPUThreadPoolExecutor)
internal::ReturnAction< R > Return(R value)