proxygen
HTTPDownstreamTest< C > Class Template Reference
Inheritance diagram for HTTPDownstreamTest< C >:
testing::Test HTTPDownstreamSessionUpgradeFlowControlTest

Public Member Functions

 HTTPDownstreamTest (std::vector< int64_t > flowControl={-1,-1,-1}, bool startImmediately=true)
 
HTTPCodec::StreamID sendRequest (const std::string &url="/", int8_t priority=0, bool eom=true)
 
HTTPCodec::StreamID sendRequest (const HTTPMessage &req, bool eom=true)
 
HTTPCodec::StreamID sendHeader ()
 
Promise< UnitsendRequestLater (HTTPMessage req, bool eof=false)
 
void SetUp () override
 
void cleanup ()
 
std::unique_ptr< testing::StrictMock< MockHTTPHandler > > addSimpleStrictHandler ()
 
std::unique_ptr< testing::NiceMock< MockHTTPHandler > > addSimpleNiceHandler ()
 
void onEOMTerminateHandlerExpectShutdown (MockHTTPHandler &handler)
 
void expectDetachSession ()
 
void addSingleByteReads (const char *data, milliseconds delay={})
 
void flushRequestsAndLoop (bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
 
void flushRequestsAndLoopN (uint64_t n, bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
 
void flushRequests (bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
 
void testSimpleUpgrade (const std::string &upgradeHeader, CodecProtocol expectedProtocol, const std::string &expectedUpgradeHeader)
 
void gracefulShutdown ()
 
void testPriorities (uint32_t numPriorities)
 
void testChunks (bool trailers)
 
void expect101 (CodecProtocol expectedProtocol, const std::string &expectedUpgrade, bool expect100=false)
 
void expectResponse (uint32_t code=200, ErrorCode errorCode=ErrorCode::NO_ERROR, bool expect100=false, bool expectGoaway=false)
 
void expectResponses (uint32_t n, uint32_t code=200, ErrorCode errorCode=ErrorCode::NO_ERROR, bool expect100=false, bool expectGoaway=false)
 
void parseOutput (HTTPCodec &clientCodec)
 
void resumeWritesInLoop ()
 
void resumeWritesAfterDelay (milliseconds delay)
 
MockByteEventTrackersetMockByteEventTracker ()
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 

Protected Attributes

EventBase eventBase_
 
TestAsyncTransporttransport_
 
folly::HHWheelTimer::UniquePtr transactionTimeouts_
 
std::vector< int64_tflowControl_
 
StrictMock< MockControllermockController_
 
HTTPDownstreamSessionhttpSession_
 
IOBufQueue requests_ {IOBufQueue::cacheChainLength()}
 
unique_ptr< HTTPCodecclientCodec_
 
NiceMock< MockHTTPCodecCallbackcallbacks_
 
IOBufQueue parseOutputStream_ {IOBufQueue::cacheChainLength()}
 
bool breakParseOutput_ {false}
 
C::Codec * rawCodec_ {nullptr}
 
HeaderIndexingStrategy testH2IndexingStrat_
 

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 ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 
 Test ()
 
virtual void TearDown ()
 

Detailed Description

template<typename C>
class HTTPDownstreamTest< C >

Definition at line 44 of file HTTPDownstreamSessionTest.cpp.

Constructor & Destructor Documentation

template<typename C>
HTTPDownstreamTest< C >::HTTPDownstreamTest ( std::vector< int64_t flowControl = { -1, -1, -1 },
bool  startImmediately = true 
)
inlineexplicit

Definition at line 46 of file HTTPDownstreamSessionTest.cpp.

47  { -1, -1, -1 },
48  bool startImmediately = true)
49  : eventBase_(),
52  flowControl_(flowControl) {
53  EXPECT_CALL(mockController_, getGracefulShutdownTimeout())
54  .WillRepeatedly(Return(std::chrono::milliseconds(0)));
55  EXPECT_CALL(mockController_, attachSession(_))
56  .WillRepeatedly(Invoke([&] (HTTPSessionBase* session) {
57  session->setPrioritySampled(true);
58  }));
59  HTTPSession::setDefaultReadBufferLimit(65536);
60  auto codec = makeServerCodec<typename C::Codec>(C::version);
61  rawCodec_ = codec.get();
62 
63  // If the codec is H2, getHeaderIndexingStrategy will be called when setting
64  // up the codec
65  if (rawCodec_->getProtocol() == CodecProtocol::HTTP_2) {
66  EXPECT_CALL(mockController_, getHeaderIndexingStrategy())
67  .WillOnce(
69  );
70  }
71 
78  mockTransportInfo /* no stats for now */,
79  nullptr);
80  for (auto& param: flowControl) {
81  if (param < 0) {
82  param = rawCodec_->getDefaultWindowSize();
83  }
84  }
85 
86  // Ensure the H2 header indexing strategy was setup correctly if applicable
87  if (rawCodec_->getProtocol() == CodecProtocol::HTTP_2) {
88  HTTP2Codec* recastedCodec = dynamic_cast<HTTP2Codec*>(rawCodec_);
89  EXPECT_EQ(
91  }
92 
93  httpSession_->setFlowControl(flowControl[0], flowControl[1],
94  flowControl[2]);
95  httpSession_->setEgressSettings({{ SettingsId::MAX_CONCURRENT_STREAMS, 80 },
96  { SettingsId::HEADER_TABLE_SIZE, 5555 },
97  { SettingsId::ENABLE_PUSH, 1 },
98  { SettingsId::ENABLE_EX_HEADERS, 1 }});
99  if (startImmediately) {
101  }
102  clientCodec_ = makeClientCodec<typename C::Codec>(C::version);
103  if (clientCodec_->getProtocol() == CodecProtocol::HTTP_2) {
104  clientCodec_->getEgressSettings()->setSetting(
105  SettingsId::ENABLE_EX_HEADERS, 1);
106  }
107  clientCodec_->generateConnectionPreface(requests_);
108  clientCodec_->setCallback(&callbacks_);
109  }
StrictMock< MockController > mockController_
const SocketAddress peerAddr
Definition: TestUtils.cpp:20
std::vector< int64_t > flowControl_
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TestAsyncTransport * transport_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
const wangle::TransportInfo mockTransportInfo
Definition: TestUtils.cpp:18
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: HTTP2Codec.h:174
ProtocolVersion version
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
folly::HHWheelTimer::UniquePtr transactionTimeouts_
folly::HHWheelTimer::UniquePtr makeTimeoutSet(EventBase *evb)
Definition: TestUtils.cpp:31
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void setFlowControl(size_t initialReceiveWindow, size_t receiveStreamWindowSize, size_t receiveSessionWindowSize) override
void setPrioritySampled(bool sampled)
NiceMock< MockHTTPCodecCallback > callbacks_
void setEgressSettings(const SettingsList &inSettings) override
HeaderIndexingStrategy testH2IndexingStrat_
unique_ptr< HTTPCodec > clientCodec_
const SocketAddress localAddr
Definition: TestUtils.cpp:19
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
HTTPDownstreamSession * httpSession_
internal::ReturnAction< R > Return(R value)

Member Function Documentation

template<typename C>
std::unique_ptr<testing::NiceMock<MockHTTPHandler> > HTTPDownstreamTest< C >::addSimpleNiceHandler ( )
inline

Definition at line 173 of file HTTPDownstreamSessionTest.cpp.

173  {
174  std::unique_ptr<testing::NiceMock<MockHTTPHandler>> handler =
175  std::make_unique<testing::NiceMock<MockHTTPHandler>>();
176 
177  // See comment above
178  auto rawHandler = handler.get();
179  EXPECT_CALL(mockController_, getRequestHandler(testing::_, testing::_))
180  .WillOnce(testing::Return(rawHandler))
181  .RetiresOnSaturation();
182 
183  EXPECT_CALL(*handler, setTransaction(testing::_))
184  .WillOnce(testing::SaveArg<0>(&handler->txn_));
185 
186  return handler;
187  }
StrictMock< MockController > mockController_
void handler(int, siginfo_t *, void *)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
template<typename C>
std::unique_ptr<testing::StrictMock<MockHTTPHandler> > HTTPDownstreamTest< C >::addSimpleStrictHandler ( )
inline

Definition at line 155 of file HTTPDownstreamSessionTest.cpp.

155  {
156  std::unique_ptr<testing::StrictMock<MockHTTPHandler>> handler =
157  std::make_unique<testing::StrictMock<MockHTTPHandler>>();
158 
159  // The ownership model here is suspect, but assume the callers won't destroy
160  // handler before it's requested
161  auto rawHandler = handler.get();
162  EXPECT_CALL(mockController_, getRequestHandler(testing::_, testing::_))
163  .WillOnce(testing::Return(rawHandler))
164  .RetiresOnSaturation();
165 
166  EXPECT_CALL(*handler, setTransaction(testing::_))
167  .WillOnce(testing::SaveArg<0>(&handler->txn_));
168 
169  return handler;
170  }
StrictMock< MockController > mockController_
void handler(int, siginfo_t *, void *)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
template<typename C>
void HTTPDownstreamTest< C >::addSingleByteReads ( const char *  data,
milliseconds  delay = {} 
)
inline

Definition at line 199 of file HTTPDownstreamSessionTest.cpp.

199  {}) {
200  for (const char* p = data; *p != '\0'; ++p) {
201  transport_->addReadEvent(p, 1, delay);
202  }
203  }
TestAsyncTransport * transport_
void addReadEvent(const void *buf, size_t buflen, std::chrono::milliseconds delayFromPrevious)
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
template<typename C>
void HTTPDownstreamTest< C >::cleanup ( )
inline

Definition at line 148 of file HTTPDownstreamSessionTest.cpp.

148  {
149  EXPECT_CALL(mockController_, detachSession(_));
151  }
StrictMock< MockController > mockController_
void dropConnection() override
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
HTTPDownstreamSession * httpSession_
template<typename C>
void HTTPDownstreamTest< C >::expect101 ( CodecProtocol  expectedProtocol,
const std::string expectedUpgrade,
bool  expect100 = false 
)
inline

Definition at line 253 of file HTTPDownstreamSessionTest.cpp.

255  {
257 
258  EXPECT_CALL(callbacks, onMessageBegin(_, _));
259  EXPECT_CALL(callbacks, onNativeProtocolUpgrade(_, _, _, _))
260  .WillOnce(
261  Invoke([this, expectedUpgrade] (HTTPCodec::StreamID,
263  const std::string&,
264  HTTPMessage& msg) {
265  EXPECT_EQ(msg.getStatusCode(), 101);
266  EXPECT_EQ(msg.getStatusMessage(), "Switching Protocols");
268  expectedUpgrade);
269  // also connection and date
270  EXPECT_EQ(msg.getHeaders().size(), 3);
271  breakParseOutput_ = true;
272  return true;
273  }));
274  // this comes before 101, but due to gmock this is backwards
275  if (expect100) {
276  EXPECT_CALL(callbacks, onMessageBegin(_, _))
277  .RetiresOnSaturation();
278  EXPECT_CALL(callbacks, onHeadersComplete(_, _))
279  .WillOnce(Invoke([] (HTTPCodec::StreamID,
280  std::shared_ptr<HTTPMessage> msg) {
281  LOG(INFO) << "100 headers";
282  EXPECT_EQ(msg->getStatusCode(), 100);
283  }))
284  .RetiresOnSaturation();
285  EXPECT_CALL(callbacks, onMessageComplete(_, _))
286  .RetiresOnSaturation();
287  }
288  clientCodec_->setCallback(&callbacks);
290  clientCodec_ = HTTPCodecFactory::getCodec(expectedProtocol,
291  TransportDirection::UPSTREAM);
292  }
void parseOutput(HTTPCodec &clientCodec)
const std::string & getStatusMessage() const
Definition: HTTPMessage.h:245
uint16_t getStatusCode() const
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
const std::string & getSingleOrEmpty(const T &nameOrCode) const
Definition: HTTPHeaders.h:420
size_t size() const
const char * string
Definition: Conv.cpp:212
unique_ptr< HTTPCodec > clientCodec_
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
std::unique_ptr< Codec > getCodec(CodecType type, int level)
template<typename C>
void HTTPDownstreamTest< C >::expectDetachSession ( )
inline

Definition at line 195 of file HTTPDownstreamSessionTest.cpp.

195  {
196  EXPECT_CALL(mockController_, detachSession(testing::_));
197  }
StrictMock< MockController > mockController_
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
template<typename C>
void HTTPDownstreamTest< C >::expectResponse ( uint32_t  code = 200,
ErrorCode  errorCode = ErrorCode::NO_ERROR,
bool  expect100 = false,
bool  expectGoaway = false 
)
inline

Definition at line 293 of file HTTPDownstreamSessionTest.cpp.

295  {
296  expectResponses(1, code, errorCode, expect100, expectGoaway);
297  }
void expectResponses(uint32_t n, uint32_t code=200, ErrorCode errorCode=ErrorCode::NO_ERROR, bool expect100=false, bool expectGoaway=false)
template<typename C>
void HTTPDownstreamTest< C >::expectResponses ( uint32_t  n,
uint32_t  code = 200,
ErrorCode  errorCode = ErrorCode::NO_ERROR,
bool  expect100 = false,
bool  expectGoaway = false 
)
inline

Definition at line 298 of file HTTPDownstreamSessionTest.cpp.

300  {
301  clientCodec_->setCallback(&callbacks_);
302  if (isParallelCodecProtocol(clientCodec_->getProtocol())) {
303  EXPECT_CALL(callbacks_, onSettings(_))
304  .WillOnce(Invoke([this] (const SettingsList& settings) {
305  if (flowControl_[0] > 0) {
306  bool foundInitialWindow = false;
307  for (const auto& setting: settings) {
308  if (setting.id == SettingsId::INITIAL_WINDOW_SIZE) {
309  EXPECT_EQ(flowControl_[0], setting.value);
310  foundInitialWindow = true;
311  }
312  }
313  EXPECT_TRUE(foundInitialWindow);
314  }
315  }));
316  }
317  if (flowControl_[2] > 0) {
318  int64_t sessionDelta =
319  flowControl_[2] - clientCodec_->getDefaultWindowSize();
320  if (clientCodec_->supportsSessionFlowControl() && sessionDelta) {
321  EXPECT_CALL(callbacks_, onWindowUpdate(0, sessionDelta));
322  }
323  }
324  if (flowControl_[1] > 0) {
325  size_t initWindow = flowControl_[0] > 0 ?
326  flowControl_[0] : clientCodec_->getDefaultWindowSize();
327  int64_t streamDelta = flowControl_[1] - initWindow;
328  if (clientCodec_->supportsStreamFlowControl() && streamDelta) {
329  EXPECT_CALL(callbacks_, onWindowUpdate(1, streamDelta));
330  }
331  }
332 
333  if (expectGoaway) {
335  ErrorCode::NO_ERROR, _));
336  }
337 
338  for (uint32_t i = 0; i < n; i++) {
339  uint8_t times = (expect100) ? 2 : 1;
340  EXPECT_CALL(callbacks_, onMessageBegin(_, _))
341  .Times(times).RetiresOnSaturation();
342  EXPECT_CALL(callbacks_, onHeadersComplete(_, _))
343  .WillOnce(Invoke([code] (HTTPCodec::StreamID,
344  std::shared_ptr<HTTPMessage> msg) {
345  EXPECT_EQ(msg->getStatusCode(), code);
346  }));
347  if (expect100) {
348  EXPECT_CALL(callbacks_, onHeadersComplete(_, _))
349  .WillOnce(Invoke([] (HTTPCodec::StreamID,
350  std::shared_ptr<HTTPMessage> msg) {
351  EXPECT_EQ(msg->getStatusCode(), 100);
352  }))
353  .RetiresOnSaturation();
354  }
355  if (errorCode != ErrorCode::NO_ERROR) {
356  EXPECT_CALL(callbacks_, onAbort(_, _))
357  .WillOnce(Invoke([errorCode] (HTTPCodec::StreamID,
358  ErrorCode error) {
359  EXPECT_EQ(error, errorCode);
360  }));
361  }
362  EXPECT_CALL(callbacks_, onBody(_, _, _)).RetiresOnSaturation();
363  EXPECT_CALL(callbacks_, onMessageComplete(_, _)).RetiresOnSaturation();
364  }
366  }
void parseOutput(HTTPCodec &clientCodec)
std::vector< int64_t > flowControl_
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static http_parser_settings settings
Definition: test.c:1529
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
NiceMock< MockHTTPCodecCallback > callbacks_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
bool isParallelCodecProtocol(CodecProtocol protocol)
unique_ptr< HTTPCodec > clientCodec_
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
Future< Unit > times(const int n, F &&thunk)
Definition: Future-inl.h:2348
template<typename C>
void HTTPDownstreamTest< C >::flushRequests ( bool  eof = false,
milliseconds  eofDelay = milliseconds(0),
milliseconds  initialDelay = milliseconds(0),
std::function< void()>  extraEventsFn = std::function<void()>() 
)
inline

Definition at line 223 of file HTTPDownstreamSessionTest.cpp.

226  {
227  transport_->addReadEvent(requests_, initialDelay);
228  if (extraEventsFn) {
229  extraEventsFn();
230  }
231  if (eof) {
232  transport_->addReadEOF(eofDelay);
233  }
235  }
TestAsyncTransport * transport_
void addReadEvent(const void *buf, size_t buflen, std::chrono::milliseconds delayFromPrevious)
void addReadEOF(std::chrono::milliseconds delayFromPrevious)
template<typename C>
void HTTPDownstreamTest< C >::flushRequestsAndLoop ( bool  eof = false,
milliseconds  eofDelay = milliseconds(0),
milliseconds  initialDelay = milliseconds(0),
std::function< void()>  extraEventsFn = std::function<void()>() 
)
inline

Definition at line 205 of file HTTPDownstreamSessionTest.cpp.

208  {
209  flushRequests(eof, eofDelay, initialDelay, extraEventsFn);
210  eventBase_.loop();
211  }
void flushRequests(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
template<typename C>
void HTTPDownstreamTest< C >::flushRequestsAndLoopN ( uint64_t  n,
bool  eof = false,
milliseconds  eofDelay = milliseconds(0),
milliseconds  initialDelay = milliseconds(0),
std::function< void()>  extraEventsFn = std::function<void()>() 
)
inline

Definition at line 213 of file HTTPDownstreamSessionTest.cpp.

216  {
217  flushRequests(eof, eofDelay, initialDelay, extraEventsFn);
218  for (uint64_t i = 0; i < n; i++) {
220  }
221  }
bool loopOnce(int flags=0)
Definition: EventBase.cpp:271
void flushRequests(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
template<typename C>
void HTTPDownstreamTest< C >::gracefulShutdown ( )
inline

Definition at line 242 of file HTTPDownstreamSessionTest.cpp.

242  {
244  clientCodec_->generateGoaway(this->requests_, 0, ErrorCode::NO_ERROR);
246  flushRequestsAndLoop(true);
247  }
void flushRequestsAndLoop(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
unique_ptr< HTTPCodec > clientCodec_
g_t g(f_t)
HTTPDownstreamSession * httpSession_
template<typename C>
void HTTPDownstreamTest< C >::onEOMTerminateHandlerExpectShutdown ( MockHTTPHandler handler)
inline

Definition at line 189 of file HTTPDownstreamSessionTest.cpp.

189  {
190  handler.expectEOM([&] { handler.terminate(); });
191  handler.expectDetachTransaction();
193  }
void expectEOM(std::function< void()> callback=std::function< void()>())
void expectDetachTransaction(std::function< void()> callback=std::function< void()>())
template<typename C>
void HTTPDownstreamTest< C >::parseOutput ( HTTPCodec clientCodec)
inline

Definition at line 368 of file HTTPDownstreamSessionTest.cpp.

368  {
369  auto writeEvents = transport_->getWriteEvents();
370  while (!breakParseOutput_ &&
371  (!writeEvents->empty() || !parseOutputStream_.empty())) {
372  if (!writeEvents->empty()) {
373  auto event = writeEvents->front();
374  auto vec = event->getIoVec();
375  for (size_t i = 0; i < event->getCount(); i++) {
377  IOBuf::copyBuffer(vec[i].iov_base, vec[i].iov_len));
378  }
379  writeEvents->pop_front();
380  }
381  uint32_t consumed = clientCodec.onIngress(*parseOutputStream_.front());
382  parseOutputStream_.split(consumed);
383  }
384  if (!breakParseOutput_) {
386  }
387  breakParseOutput_ = false;
388  }
std::unique_ptr< folly::IOBuf > split(size_t n)
Definition: IOBufQueue.h:420
virtual size_t onIngress(const folly::IOBuf &buf)=0
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
size_t chainLength() const
Definition: IOBufQueue.h:492
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
bool empty() const
Definition: IOBufQueue.h:503
TestAsyncTransport * transport_
std::deque< std::shared_ptr< WriteEvent > > * getWriteEvents()
Definition: Traits.h:588
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
template<typename C>
void HTTPDownstreamTest< C >::resumeWritesAfterDelay ( milliseconds  delay)
inline

Definition at line 394 of file HTTPDownstreamSessionTest.cpp.

394  {
396  delay.count());
397  }
TestAsyncTransport * transport_
void runAfterDelay(Func cob, uint32_t milliseconds, InternalEnum internal=InternalEnum::NORMAL)
template<typename C>
void HTTPDownstreamTest< C >::resumeWritesInLoop ( )
inline

Definition at line 390 of file HTTPDownstreamSessionTest.cpp.

390  {
392  }
TestAsyncTransport * transport_
void runInLoop(LoopCallback *callback, bool thisIteration=false)
Definition: EventBase.cpp:520
template<typename C>
HTTPCodec::StreamID HTTPDownstreamTest< C >::sendHeader ( )
inline

Definition at line 126 of file HTTPDownstreamSessionTest.cpp.

126  {
127  return sendRequest("/", 0, false);
128  }
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
template<typename C>
HTTPCodec::StreamID HTTPDownstreamTest< C >::sendRequest ( const std::string url = "/",
int8_t  priority = 0,
bool  eom = true 
)
inline

Definition at line 111 of file HTTPDownstreamSessionTest.cpp.

113  {
114  auto req = getGetRequest();
115  req.setURL(url);
116  req.setPriority(priority);
117  return sendRequest(req, eom);
118  }
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
template<typename C>
HTTPCodec::StreamID HTTPDownstreamTest< C >::sendRequest ( const HTTPMessage req,
bool  eom = true 
)
inline

Definition at line 120 of file HTTPDownstreamSessionTest.cpp.

120  {
121  auto streamID = clientCodec_->createStream();
122  clientCodec_->generateHeader(requests_, streamID, req, eom);
123  return streamID;
124  }
unique_ptr< HTTPCodec > clientCodec_
uint32_t streamID
Definition: SPDYCodec.cpp:131
template<typename C>
Promise<Unit> HTTPDownstreamTest< C >::sendRequestLater ( HTTPMessage  req,
bool  eof = false 
)
inline

Definition at line 130 of file HTTPDownstreamSessionTest.cpp.

130  {
131  Promise<Unit> reqp;
132  reqp.getFuture().then(&eventBase_, [=] {
133  sendRequest(req);
134  transport_->addReadEvent(requests_, milliseconds(0));
135  if (eof) {
136  transport_->addReadEOF(milliseconds(0));
137  }
138  });
139  return reqp;
140  }
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
TestAsyncTransport * transport_
void addReadEvent(const void *buf, size_t buflen, std::chrono::milliseconds delayFromPrevious)
Future< T > getFuture()
Definition: Promise-inl.h:97
void addReadEOF(std::chrono::milliseconds delayFromPrevious)
template<typename C>
MockByteEventTracker* HTTPDownstreamTest< C >::setMockByteEventTracker ( )
inline

Definition at line 399 of file HTTPDownstreamSessionTest.cpp.

399  {
400  auto byteEventTracker = new MockByteEventTracker(nullptr);
402  std::unique_ptr<ByteEventTracker>(byteEventTracker));
403  EXPECT_CALL(*byteEventTracker, preSend(_, _, _))
404  .WillRepeatedly(Return(0));
405  EXPECT_CALL(*byteEventTracker, drainByteEvents())
406  .WillRepeatedly(Return(0));
407  EXPECT_CALL(*byteEventTracker, processByteEvents(_, _))
408  .WillRepeatedly(Invoke([]
409  (std::shared_ptr<ByteEventTracker> self,
410  uint64_t bytesWritten) {
411  return self->ByteEventTracker::processByteEvents(
412  self,
413  bytesWritten);
414  }));
415 
416  return byteEventTracker;
417  }
void setByteEventTracker(std::shared_ptr< ByteEventTracker > byteEventTracker)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
HTTPDownstreamSession * httpSession_
internal::ReturnAction< R > Return(R value)
template<typename C>
void HTTPDownstreamTest< C >::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 142 of file HTTPDownstreamSessionTest.cpp.

142  {
144  HTTPSession::setDefaultWriteBufferLimit(65536);
145  HTTP2PriorityQueue::setNodeLifetime(std::chrono::milliseconds(2));
146  }
static EventBaseManager * get()
template<class C >
void HTTPDownstreamTest< C >::testChunks ( bool  trailers)

Definition at line 1365 of file HTTPDownstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, g(), handler(), and i.

1365  {
1366  InSequence enforceOrder;
1367 
1369  handler->expectHeaders();
1370  handler->expectEOM([&handler, trailers] () {
1371  handler->sendChunkedReplyWithBody(200, 100, 17, trailers);
1372  });
1373  handler->expectDetachTransaction();
1374 
1375  HTTPSession::DestructorGuard g(httpSession_);
1376  sendRequest();
1377  flushRequestsAndLoop(true, milliseconds(0));
1378 
1379  EXPECT_CALL(callbacks_, onMessageBegin(1, _))
1380  .Times(1);
1381  EXPECT_CALL(callbacks_, onHeadersComplete(1, _))
1382  .Times(1);
1383  for (int i = 0; i < 6; i++) {
1384  EXPECT_CALL(callbacks_, onChunkHeader(1, _));
1385  EXPECT_CALL(callbacks_, onBody(1, _, _));
1386  EXPECT_CALL(callbacks_, onChunkComplete(1));
1387  }
1388  if (trailers) {
1389  EXPECT_CALL(callbacks_, onTrailersComplete(1, _));
1390  }
1391  EXPECT_CALL(callbacks_, onMessageComplete(1, _));
1392 
1395 }
void parseOutput(HTTPCodec &clientCodec)
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
void handler(int, siginfo_t *, void *)
void flushRequestsAndLoop(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
NiceMock< MockHTTPCodecCallback > callbacks_
unique_ptr< HTTPCodec > clientCodec_
g_t g(f_t)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
std::unique_ptr< testing::StrictMock< MockHTTPHandler > > addSimpleStrictHandler()
HTTPDownstreamSession * httpSession_
template<class C >
void HTTPDownstreamTest< C >::testPriorities ( uint32_t  numPriorities)

Definition at line 2170 of file HTTPDownstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_GE, EXPECT_LE, handler(), i, testing::Invoke(), folly::gen::move, and uint32_t.

2170  {
2171  uint32_t iterations = 10;
2172  uint32_t maxPriority = numPriorities - 1;
2173  std::vector<std::unique_ptr<testing::NiceMock<MockHTTPHandler>>> handlers;
2174  for (int pri = numPriorities - 1; pri >= 0; pri--) {
2175  for (uint32_t i = 0; i < iterations; i++) {
2176  sendRequest("/", pri * (8 / numPriorities));
2177  InSequence handlerSequence;
2178  auto handler = addSimpleNiceHandler();
2179  auto rawHandler = handler.get();
2180  handlers.push_back(std::move(handler));
2181  rawHandler->expectHeaders();
2182  rawHandler->expectEOM([rawHandler] {
2183  rawHandler->sendReplyWithBody(200, 1000);
2184  });
2185  rawHandler->expectDetachTransaction([] { });
2186  }
2187  }
2188 
2189  auto buf = requests_.move();
2190  buf->coalesce();
2191  requests_.append(std::move(buf));
2192 
2194 
2195  std::list<HTTPCodec::StreamID> streams;
2196  EXPECT_CALL(callbacks_, onMessageBegin(_, _))
2197  .Times(iterations * numPriorities);
2198  EXPECT_CALL(callbacks_, onHeadersComplete(_, _))
2199  .Times(iterations * numPriorities);
2200  // body is variable and hence ignored
2201  EXPECT_CALL(callbacks_, onMessageComplete(_, _))
2202  .Times(iterations * numPriorities)
2203  .WillRepeatedly(Invoke([&](HTTPCodec::StreamID stream, bool /*upgrade*/) {
2204  streams.push_back(stream);
2205  }));
2206 
2208 
2209  // transactions finish in priority order (higher streamIDs first)
2210  EXPECT_EQ(streams.size(), iterations * numPriorities);
2211  auto txn = streams.begin();
2212  for (int band = maxPriority; band >= 0; band--) {
2213  auto upperID = iterations * 2 * (band + 1);
2214  auto lowerID = iterations * 2 * band;
2215  for (uint32_t i = 0; i < iterations; i++) {
2216  EXPECT_LE(lowerID, (uint32_t)*txn);
2217  EXPECT_GE(upperID, (uint32_t)*txn);
2218  ++txn;
2219  }
2220  }
2221 }
#define EXPECT_LE(val1, val2)
Definition: gtest.h:1928
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
void parseOutput(HTTPCodec &clientCodec)
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
void handler(int, siginfo_t *, void *)
void flushRequestsAndLoop(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
NiceMock< MockHTTPCodecCallback > callbacks_
unique_ptr< HTTPCodec > clientCodec_
std::unique_ptr< testing::NiceMock< MockHTTPHandler > > addSimpleNiceHandler()
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
template<class C >
void HTTPDownstreamTest< C >::testSimpleUpgrade ( const std::string upgradeHeader,
CodecProtocol  expectedProtocol,
const std::string expectedUpgradeHeader 
)

Definition at line 1864 of file HTTPDownstreamSessionTest.cpp.

References ASSERT_NE, codec, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, proxygen::HTTP2Codec::getHeaderIndexingStrategy(), proxygen::getUpgradeRequest(), handler(), proxygen::http2::kProtocolCleartextString, and testing::Return().

1867  {
1868  this->rawCodec_->setAllowedUpgradeProtocols({expectedUpgradeHeader});
1869 
1871 
1872  HeaderIndexingStrategy testH2IndexingStrat;
1873  handler->expectHeaders();
1874  EXPECT_CALL(mockController_, onSessionCodecChange(httpSession_));
1875  handler->expectEOM(
1876  [&handler, expectedProtocol, expectedUpgradeHeader, &testH2IndexingStrat] {
1877  EXPECT_FALSE(handler->txn_->getSetupTransportInfo().secure);
1878  EXPECT_EQ(*handler->txn_->getSetupTransportInfo().appProtocol,
1879  expectedUpgradeHeader);
1880  if (expectedProtocol == CodecProtocol::HTTP_2) {
1881  const HTTP2Codec* codec = dynamic_cast<const HTTP2Codec*>(
1882  &handler->txn_->getTransport().getCodec());
1883  ASSERT_NE(codec, nullptr);
1884  EXPECT_EQ(codec->getHeaderIndexingStrategy(), &testH2IndexingStrat);
1885  }
1886  handler->sendReplyWithBody(200, 100);
1887  });
1888  handler->expectDetachTransaction();
1889 
1890  if (expectedProtocol == CodecProtocol::HTTP_2) {
1891  EXPECT_CALL(mockController_, getHeaderIndexingStrategy())
1892  .WillOnce(
1893  Return(&testH2IndexingStrat)
1894  );
1895  }
1896 
1897  HTTPMessage req = getUpgradeRequest(upgradeHeader);
1898  if (upgradeHeader == http2::kProtocolCleartextString) {
1899  HTTP2Codec::requestUpgrade(req);
1900  }
1901  sendRequest(req);
1903 
1904  expect101(expectedProtocol, expectedUpgradeHeader);
1905  expectResponse();
1906 
1907  gracefulShutdown();
1908 }
void expect101(CodecProtocol expectedProtocol, const std::string &expectedUpgrade, bool expect100=false)
StrictMock< MockController > mockController_
HTTPCodec::StreamID sendRequest(const std::string &url="/", int8_t priority=0, bool eom=true)
const std::string kProtocolCleartextString
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
CodecFactory codec
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: HTTP2Codec.h:174
void handler(int, siginfo_t *, void *)
void flushRequestsAndLoop(bool eof=false, milliseconds eofDelay=milliseconds(0), milliseconds initialDelay=milliseconds(0), std::function< void()> extraEventsFn=std::function< void()>())
void expectResponse(uint32_t code=200, ErrorCode errorCode=ErrorCode::NO_ERROR, bool expect100=false, bool expectGoaway=false)
#define EXPECT_CALL(obj, call)
std::unique_ptr< testing::StrictMock< MockHTTPHandler > > addSimpleStrictHandler()
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
HTTPDownstreamSession * httpSession_
HTTPMessage getUpgradeRequest(const std::string &upgradeHeader, HTTPMethod method, uint32_t bodyLen)
Definition: TestUtils.cpp:161
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
internal::ReturnAction< R > Return(R value)

Member Data Documentation

template<typename C>
bool HTTPDownstreamTest< C >::breakParseOutput_ {false}
protected

Definition at line 430 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
NiceMock<MockHTTPCodecCallback> HTTPDownstreamTest< C >::callbacks_
protected

Definition at line 428 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
unique_ptr<HTTPCodec> HTTPDownstreamTest< C >::clientCodec_
protected

Definition at line 427 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
EventBase HTTPDownstreamTest< C >::eventBase_
protected

Definition at line 420 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
std::vector<int64_t> HTTPDownstreamTest< C >::flowControl_
protected

Definition at line 423 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
HTTPDownstreamSession* HTTPDownstreamTest< C >::httpSession_
protected

Definition at line 425 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
StrictMock<MockController> HTTPDownstreamTest< C >::mockController_
protected

Definition at line 424 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
IOBufQueue HTTPDownstreamTest< C >::parseOutputStream_ {IOBufQueue::cacheChainLength()}
protected

Definition at line 429 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
C::Codec* HTTPDownstreamTest< C >::rawCodec_ {nullptr}
protected

Definition at line 431 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
IOBufQueue HTTPDownstreamTest< C >::requests_ {IOBufQueue::cacheChainLength()}
protected

Definition at line 426 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
HeaderIndexingStrategy HTTPDownstreamTest< C >::testH2IndexingStrat_
protected

Definition at line 432 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
folly::HHWheelTimer::UniquePtr HTTPDownstreamTest< C >::transactionTimeouts_
protected

Definition at line 422 of file HTTPDownstreamSessionTest.cpp.

template<typename C>
TestAsyncTransport* HTTPDownstreamTest< C >::transport_
protected

Definition at line 421 of file HTTPDownstreamSessionTest.cpp.


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