proxygen
AcceptRoutingHandlerTest.cpp File Reference
#include "Mocks.h"

Go to the source code of this file.

Classes

class  TestClientPipelineFactory
 
class  AcceptRoutingHandlerTest
 

Typedefs

using TestServer = ServerBootstrap< DefaultPipeline >
 
using TestClient = ClientBootstrap< DefaultPipeline >
 

Functions

 TEST_F (AcceptRoutingHandlerTest, ParseRoutingDataSuccess)
 
 TEST_F (AcceptRoutingHandlerTest, SocketErrorInRoutingPipeline)
 
 TEST_F (AcceptRoutingHandlerTest, OnNewConnectionWithBadSocket)
 
 TEST_F (AcceptRoutingHandlerTest, RoutingPipelineErasedOnlyOnce)
 

Typedef Documentation

Function Documentation

TEST_F ( AcceptRoutingHandlerTest  ,
ParseRoutingDataSuccess   
)

Definition at line 170 of file AcceptRoutingHandlerTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, testing::Invoke(), and fizz::detail::read().

170  {
171  // Server receives data, and parses routing data
172  EXPECT_CALL(*routingDataHandler_, transportActive(_));
173  EXPECT_CALL(*routingDataHandler_, parseRoutingData(_, _))
174  .WillOnce(
175  Invoke([&](folly::IOBufQueue& /*bufQueue*/,
176  MockRoutingDataHandler::RoutingData& /*routingData*/) {
177  VLOG(4) << "Parsed routing data";
178  return true;
179  }));
180 
181  // Downstream pipeline is created, and its handler receives events
182  boost::barrier barrier(2);
183  EXPECT_CALL(*downstreamHandler_, transportActive(_));
184  EXPECT_CALL(*downstreamHandler_, read(_, _))
185  .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/,
186  IOBufQueue& /*bufQueue*/) {
187  VLOG(4) << "Downstream received a read";
188  }));
189  EXPECT_CALL(*downstreamHandler_, readEOF(_))
190  .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* ctx) {
191  VLOG(4) << "Downstream EOF";
192  ctx->fireClose();
193  barrier.wait();
194  }));
195  EXPECT_CALL(*downstreamHandler_, transportInactive(_));
196 
197  // Send client request that triggers server processing
198  clientConnectAndCleanClose();
199 
200  barrier.wait();
201 
202  // Routing pipeline has been erased
203  EXPECT_EQ(0, acceptRoutingHandler_->getRoutingPipelineCount());
204 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( AcceptRoutingHandlerTest  ,
SocketErrorInRoutingPipeline   
)

Definition at line 206 of file AcceptRoutingHandlerTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, wangle::PipelineBase::getTransport(), testing::Invoke(), folly::gen::move, and wangle::Pipeline< R, W >::writeException().

206  {
207  // Server receives data, and parses routing data
208  boost::barrier barrierConnect(2);
209  EXPECT_CALL(*routingDataHandler_, transportActive(_));
210  EXPECT_CALL(*routingDataHandler_, parseRoutingData(_, _))
211  .WillOnce(
212  Invoke([&](folly::IOBufQueue& /*bufQueue*/,
213  MockRoutingDataHandler::RoutingData& /*routingData*/) {
214  VLOG(4) << "Need more data to be parse.";
215  barrierConnect.wait();
216  return false;
217  }));
218 
219  // Send client request that triggers server processing
220  auto futureClientPipeline = clientConnectAndWrite();
221 
222  // Socket exception after routing pipeline had been created
223  barrierConnect.wait();
224  boost::barrier barrierException(2);
225  std::move(futureClientPipeline).thenValue([](DefaultPipeline* clientPipeline) {
226  clientPipeline->getTransport()->getEventBase()->runInEventBaseThread(
227  [clientPipeline]() {
228  clientPipeline->writeException(
229  std::runtime_error("Socket error while expecting routing data."));
230  });
231  });
232  EXPECT_CALL(*routingDataHandler_, readException(_, _))
233  .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/,
235  VLOG(4) << "Routing data handler Exception";
236  acceptRoutingHandler_->onError(kConnId0, ex);
237  barrierException.wait();
238  }));
239  barrierException.wait();
240 
241  // Downstream pipeline is not created
242  EXPECT_CALL(*downstreamHandler_, transportActive(_)).Times(0);
243  delete downstreamHandler_;
244 
245  // Routing pipeline has been erased
246  EXPECT_EQ(0, acceptRoutingHandler_->getRoutingPipelineCount());
247 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::shared_ptr< folly::AsyncTransport > getTransport()
Definition: Pipeline.h:65
std::enable_if<!std::is_same< T, folly::Unit >::value, folly::Future< folly::Unit > >::type writeException(folly::exception_wrapper e)
Definition: Pipeline-inl.h:246
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( AcceptRoutingHandlerTest  ,
OnNewConnectionWithBadSocket   
)

Definition at line 249 of file AcceptRoutingHandlerTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, and testing::Invoke().

249  {
250  // Routing data handler doesn't receive any data
251  EXPECT_CALL(*routingDataHandler_, parseRoutingData(_, _)).Times(0);
252 
253  // Downstream pipeline is not created
254  EXPECT_CALL(*downstreamHandler_, transportActive(_)).Times(0);
255  delete downstreamHandler_;
256 
257  // Send client request that triggers server processing
258  boost::barrier barrierConnect(2);
259  EXPECT_CALL(*routingDataHandler_, transportActive(_))
260  .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* /*ctx*/) {
261  barrierConnect.wait();
262  }));
263  auto futureClientPipeline = justClientConnect();
264  barrierConnect.wait();
265  futureClientPipeline.wait();
266 
267  // Expect an exception on the routing data handler
268  boost::barrier barrierException(2);
269  EXPECT_CALL(*routingDataHandler_, readException(_, _))
270  .WillOnce(Invoke(
271  [&](MockBytesToBytesHandler::Context* /*ctx*/,
272  folly::exception_wrapper /*ex*/) { barrierException.wait(); }));
273  sendClientException(futureClientPipeline.value());
274  barrierException.wait();
275 
276  // Routing pipeline has been added
277  EXPECT_EQ(1, acceptRoutingHandler_->getRoutingPipelineCount());
278 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( AcceptRoutingHandlerTest  ,
RoutingPipelineErasedOnlyOnce   
)

Definition at line 280 of file AcceptRoutingHandlerTest.cpp.

280  {
281  // Simulate client socket throwing an exception, while routing data handler
282  // parsed data successfully.
283  acceptPipeline_->readException(
284  std::runtime_error("An exception from the socket."));
285  acceptRoutingHandler_->onRoutingData(kConnId0, routingData_);
286 }