proxygen
HTTPUpstreamTest< C > Class Template Reference
Inheritance diagram for HTTPUpstreamTest< C >:
testing::Test proxygen::HTTPSessionBase::InfoCallback HTTPUpstreamRecvStreamTest TimeoutableHTTPUpstreamTest< C >

Public Member Functions

 HTTPUpstreamTest (std::vector< int64_t > flowControl={-1,-1,-1})
 
void resumeWrites ()
 
virtual void onWriteChain (folly::AsyncTransportWrapper::WriteCallback *callback, std::shared_ptr< IOBuf > iob, WriteFlags)
 
void handleWrite (folly::AsyncTransportWrapper::WriteCallback *callback)
 
void SetUp () override
 
void commonSetUp (unique_ptr< HTTPCodec > codec)
 
unique_ptr< typename C::Codec > makeServerCodec ()
 
void enableExHeader (typename C::Codec *serverCodec)
 
void parseOutput (HTTPCodec &serverCodec)
 
void readAndLoop (const std::string &input)
 
void readAndLoop (IOBuf *buf)
 
void readAndLoop (const uint8_t *input, size_t length)
 
void testBasicRequest ()
 
void testBasicRequestHttp10 (bool keepalive)
 
void onCreate (const HTTPSessionBase &) override
 
void onDestroy (const HTTPSessionBase &) override
 
void onSettingsOutgoingStreamsFull (const HTTPSessionBase &) override
 
void onSettingsOutgoingStreamsNotFull (const HTTPSessionBase &) override
 
void TearDown () override
 
std::unique_ptr< StrictMock< MockHTTPHandler > > openTransaction (bool expectStartPaused=false)
 
std::unique_ptr< NiceMock< MockHTTPHandler > > openNiceTransaction (bool expectStartPaused=false)
 
void testSimpleUpgrade (const std::string &upgradeReqHeader, const std::string &upgradeRespHeader, CodecProtocol respCodecVersion)
 
MockByteEventTrackersetMockByteEventTracker ()
 
- Public Member Functions inherited from testing::Test
virtual ~Test ()
 
virtual ~Test ()
 
virtual ~Test ()
 
- Public Member Functions inherited from proxygen::HTTPSessionBase::InfoCallback
virtual ~InfoCallback ()
 
virtual void onFullHandshakeCompletion (const HTTPSessionBase &)
 
virtual void onIngressError (const HTTPSessionBase &, ProxygenError)
 
virtual void onIngressEOF ()
 
virtual void onRead (const HTTPSessionBase &, size_t)
 
virtual void onWrite (const HTTPSessionBase &, size_t)
 
virtual void onRequestBegin (const HTTPSessionBase &)
 
virtual void onRequestEnd (const HTTPSessionBase &, uint32_t)
 
virtual void onActivateConnection (const HTTPSessionBase &)
 
virtual void onDeactivateConnection (const HTTPSessionBase &)
 
virtual void onIngressMessage (const HTTPSessionBase &, const HTTPMessage &)
 
virtual void onIngressLimitExceeded (const HTTPSessionBase &)
 
virtual void onIngressPaused (const HTTPSessionBase &)
 
virtual void onTransactionDetached (const HTTPSessionBase &)
 
virtual void onPingReplySent (int64_t)
 
virtual void onPingReplyReceived ()
 
virtual void onFlowControlWindowClosed (const HTTPSessionBase &)
 
virtual void onEgressBuffered (const HTTPSessionBase &)
 
virtual void onEgressBufferCleared (const HTTPSessionBase &)
 
virtual void onSettings (const HTTPSessionBase &, const SettingsList &)
 
virtual void onSettingsAck (const HTTPSessionBase &)
 

Protected Attributes

bool sessionCreated_ {false}
 
bool sessionDestroyed_ {false}
 
bool transactionsFull_ {false}
 
bool transportGood_ {true}
 
EventBase eventBase_
 
EventBaseeventBasePtr_ {&eventBase_}
 
MockAsyncTransporttransport_
 
folly::AsyncTransportWrapper::ReadCallbackreadCallback_ {nullptr}
 
folly::AsyncTransport::ReplaySafetyCallbackreplaySafetyCallback_ {nullptr}
 
folly::HHWheelTimer::UniquePtr transactionTimeouts_
 
std::vector< int64_tflowControl_
 
wangle::TransportInfo mockTransportInfo_
 
SocketAddress localAddr_ {"127.0.0.1", 80}
 
SocketAddress peerAddr_ {"127.0.0.1", 12345}
 
HTTPUpstreamSessionhttpSession_ {nullptr}
 
IOBufQueue writes_ {IOBufQueue::cacheChainLength()}
 
std::vector< folly::AsyncTransportWrapper::WriteCallback * > cbs_
 
bool failWrites_ {false}
 
bool pauseWrites_ {false}
 
bool writeInLoop_ {false}
 

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

template<class C>
class HTTPUpstreamTest< C >

Definition at line 136 of file HTTPUpstreamSessionTest.cpp.

Constructor & Destructor Documentation

template<class C>
HTTPUpstreamTest< C >::HTTPUpstreamTest ( std::vector< int64_t flowControl = {-1, -1, -1})
inlineexplicit

Definition at line 139 of file HTTPUpstreamSessionTest.cpp.

139  {-1, -1, -1})
140  : eventBase_(),
143  &eventBase_,
144  std::chrono::milliseconds(
146  TimeoutManager::InternalEnum::INTERNAL,
147  std::chrono::milliseconds(500))),
148  flowControl_(flowControl) {}
static int DEFAULT_TICK_INTERVAL
Definition: HHWheelTimer.h:163
static UniquePtr newTimer(Args &&...args)
Definition: HHWheelTimer.h:61
MockAsyncTransport * transport_
std::vector< int64_t > flowControl_
folly::HHWheelTimer::UniquePtr transactionTimeouts_

Member Function Documentation

template<class C>
void HTTPUpstreamTest< C >::commonSetUp ( unique_ptr< HTTPCodec codec)
inline

Definition at line 191 of file HTTPUpstreamSessionTest.cpp.

191  {
192  HTTPSession::setDefaultReadBufferLimit(65536);
193  HTTPSession::setDefaultWriteBufferLimit(65536);
194  EXPECT_CALL(*transport_, writeChain(_, _, _))
195  .WillRepeatedly(Invoke(this, &HTTPUpstreamTest<C>::onWriteChain));
196  EXPECT_CALL(*transport_, setReadCB(_))
197  .WillRepeatedly(SaveArg<0>(&readCallback_));
198  EXPECT_CALL(*transport_, getReadCB())
199  .WillRepeatedly(Return(readCallback_));
201  .WillRepeatedly(ReturnPointee(&eventBasePtr_));
202  EXPECT_CALL(*transport_, good())
203  .WillRepeatedly(ReturnPointee(&transportGood_));
204  EXPECT_CALL(*transport_, closeNow())
205  .WillRepeatedly(Assign(&transportGood_, false));
206  EXPECT_CALL(*transport_, isReplaySafe())
207  .WillOnce(Return(false));
208  EXPECT_CALL(*transport_, setReplaySafetyCallback(_))
209  .WillRepeatedly(SaveArg<0>(&replaySafetyCallback_));
210  EXPECT_CALL(*transport_, attachEventBase(_))
211  .WillRepeatedly(SaveArg<0>(&eventBasePtr_));
212 
213  for (auto& param: flowControl_) {
214  if (param < 0) {
215  param = codec->getDefaultWindowSize();
216  }
217  }
219  transactionTimeouts_.get(),
222  std::move(codec),
223  mockTransportInfo_, this);
224  httpSession_->setFlowControl(flowControl_[0], flowControl_[1],
225  flowControl_[2]);
227  httpSession_->setEgressSettings({{SettingsId::ENABLE_EX_HEADERS, 1}});
229  eventBase_.loop();
230  ASSERT_EQ(this->sessionDestroyed_, false);
231  }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
folly::AsyncTransportWrapper::ReadCallback * readCallback_
void setMaxConcurrentOutgoingStreams(uint32_t num)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
EventBase * getEventBase()
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
HTTPUpstreamSession * httpSession_
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void setFlowControl(size_t initialReceiveWindow, size_t receiveStreamWindowSize, size_t receiveSessionWindowSize) override
virtual uint32_t getDefaultWindowSize() const
Definition: HTTPCodec.h:680
wangle::TransportInfo mockTransportInfo_
folly::AsyncTransport::ReplaySafetyCallback * replaySafetyCallback_
void setEgressSettings(const SettingsList &inSettings) override
MockAsyncTransport * transport_
std::vector< int64_t > flowControl_
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
folly::HHWheelTimer::UniquePtr transactionTimeouts_
internal::ReturnAction< R > Return(R value)
template<class C>
void HTTPUpstreamTest< C >::enableExHeader ( typename C::Codec *  serverCodec)
inline

Definition at line 237 of file HTTPUpstreamSessionTest.cpp.

237  {
238  if (!serverCodec || serverCodec->getProtocol() != CodecProtocol::HTTP_2) {
239  return;
240  }
241 
242  auto clientCodec = makeClientCodec<HTTP2Codec>(2);
243  folly::IOBufQueue c2s{IOBufQueue::cacheChainLength()};
244  clientCodec->getEgressSettings()->setSetting(
245  SettingsId::ENABLE_EX_HEADERS, 1);
246  clientCodec->generateConnectionPreface(c2s);
247  clientCodec->generateSettings(c2s);
248 
249  // set ENABLE_EX_HEADERS to 1 in egressSettings
250  serverCodec->getEgressSettings()->setSetting(
251  SettingsId::ENABLE_EX_HEADERS, 1);
252  // set ENABLE_EX_HEADERS to 1 in ingressSettings
253  auto setup = c2s.move();
254  serverCodec->onIngress(*setup);
255  }
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
template<class C>
void HTTPUpstreamTest< C >::handleWrite ( folly::AsyncTransportWrapper::WriteCallback callback)
inline

Definition at line 172 of file HTTPUpstreamSessionTest.cpp.

172  {
173  if (failWrites_) {
175  callback->writeErr(0, ex);
176  } else {
177  if (writeInLoop_) {
178  eventBase_.runInLoop([&] {
179  callback->writeSuccess();
180  });
181  } else {
182  callback->writeSuccess();
183  }
184  }
185  }
string UNKNOWN
Definition: tokenize.py:53
void runInLoop(LoopCallback *callback, bool thisIteration=false)
Definition: EventBase.cpp:520
virtual void writeSuccess() noexcept=0
virtual void writeErr(size_t bytesWritten, const AsyncSocketException &ex) noexcept=0
template<class C>
unique_ptr<typename C::Codec> HTTPUpstreamTest< C >::makeServerCodec ( )
inline

Definition at line 233 of file HTTPUpstreamSessionTest.cpp.

233  {
234  return ::makeServerCodec<typename C::Codec>(C::version);
235  }
ProtocolVersion version
template<class C>
void HTTPUpstreamTest< C >::onCreate ( const HTTPSessionBase )
inlineoverridevirtual

Reimplemented from proxygen::HTTPSessionBase::InfoCallback.

Definition at line 297 of file HTTPUpstreamSessionTest.cpp.

template<class C>
void HTTPUpstreamTest< C >::onDestroy ( const HTTPSessionBase )
inlineoverridevirtual

Reimplemented from proxygen::HTTPSessionBase::InfoCallback.

Definition at line 298 of file HTTPUpstreamSessionTest.cpp.

template<class C>
void HTTPUpstreamTest< C >::onSettingsOutgoingStreamsFull ( const HTTPSessionBase )
inlineoverridevirtual

Reimplemented from proxygen::HTTPSessionBase::InfoCallback.

Definition at line 299 of file HTTPUpstreamSessionTest.cpp.

299  {
300  transactionsFull_ = true;
301  }
template<class C>
void HTTPUpstreamTest< C >::onSettingsOutgoingStreamsNotFull ( const HTTPSessionBase )
inlineoverridevirtual

Reimplemented from proxygen::HTTPSessionBase::InfoCallback.

Definition at line 302 of file HTTPUpstreamSessionTest.cpp.

302  {
303  transactionsFull_ = false;
304  }
template<class C>
virtual void HTTPUpstreamTest< C >::onWriteChain ( folly::AsyncTransportWrapper::WriteCallback callback,
std::shared_ptr< IOBuf iob,
WriteFlags   
)
inlinevirtual

Definition at line 158 of file HTTPUpstreamSessionTest.cpp.

161  {
162  if (pauseWrites_) {
163  cbs_.push_back(callback);
164  return; // let write requests timeout
165  }
166  auto mybuf = iob->clone();
167  mybuf->unshare();
168  writes_.append(std::move(mybuf));
169  handleWrite(callback);
170  }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< folly::AsyncTransportWrapper::WriteCallback * > cbs_
void handleWrite(folly::AsyncTransportWrapper::WriteCallback *callback)
template<class C>
std::unique_ptr<NiceMock<MockHTTPHandler> > HTTPUpstreamTest< C >::openNiceTransaction ( bool  expectStartPaused = false)
inline

Definition at line 326 of file HTTPUpstreamSessionTest.cpp.

327  {
328  // Returns a mock handler with txn_ field set in it
329  auto handler = std::make_unique<NiceMock<MockHTTPHandler>>();
330  handler->expectTransaction();
331  if (expectStartPaused) {
332  handler->expectEgressPaused();
333  }
334  auto txn = httpSession_->newTransaction(handler.get());
335  EXPECT_EQ(txn, handler->txn_);
336  return handler;
337  }
HTTPTransaction * newTransaction(HTTPTransaction::Handler *handler) override
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
HTTPUpstreamSession * httpSession_
template<class C>
std::unique_ptr<StrictMock<MockHTTPHandler> > HTTPUpstreamTest< C >::openTransaction ( bool  expectStartPaused = false)
inline

Definition at line 313 of file HTTPUpstreamSessionTest.cpp.

314  {
315  // Returns a mock handler with txn_ field set in it
316  auto handler = std::make_unique<StrictMock<MockHTTPHandler>>();
317  handler->expectTransaction();
318  if (expectStartPaused) {
319  handler->expectEgressPaused();
320  }
321  auto txn = httpSession_->newTransaction(handler.get());
322  EXPECT_EQ(txn, handler->txn_);
323  return handler;
324  }
HTTPTransaction * newTransaction(HTTPTransaction::Handler *handler) override
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
HTTPUpstreamSession * httpSession_
template<class C>
void HTTPUpstreamTest< C >::parseOutput ( HTTPCodec serverCodec)
inline

Definition at line 257 of file HTTPUpstreamSessionTest.cpp.

257  {
259  while (!writes_.empty() && consumed > 0) {
260  consumed = serverCodec.onIngress(*writes_.front());
261  writes_.split(consumed);
262  }
264  }
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
LogLevel max
Definition: LogLevel.cpp:31
bool empty() const
Definition: IOBufQueue.h:503
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
template<class C>
void HTTPUpstreamTest< C >::readAndLoop ( const std::string input)
inline

Definition at line 266 of file HTTPUpstreamSessionTest.cpp.

266  {
267  readAndLoop((const uint8_t *)input.data(), input.length());
268  }
void readAndLoop(const std::string &input)
template<class C>
void HTTPUpstreamTest< C >::readAndLoop ( IOBuf buf)
inline

Definition at line 270 of file HTTPUpstreamSessionTest.cpp.

270  {
271  buf->coalesce();
272  readAndLoop(buf->data(), buf->length());
273  }
ByteRange coalesce()
Definition: IOBuf.h:1095
const uint8_t * data() const
Definition: IOBuf.h:499
void readAndLoop(const std::string &input)
std::size_t length() const
Definition: IOBuf.h:533
template<class C>
void HTTPUpstreamTest< C >::readAndLoop ( const uint8_t input,
size_t  length 
)
inline

Definition at line 275 of file HTTPUpstreamSessionTest.cpp.

275  {
276  CHECK_NOTNULL(readCallback_);
277  void* buf;
278  size_t bufSize;
279  while (length > 0) {
280  readCallback_->getReadBuffer(&buf, &bufSize);
281  // This is somewhat specific to our implementation, but currently we
282  // always return at least some space from getReadBuffer
283  CHECK_GT(bufSize, 0);
284  bufSize = std::min(bufSize, length);
285  memcpy(buf, input, bufSize);
287  eventBasePtr_->loop();
288  length -= bufSize;
289  input += bufSize;
290  }
291  }
virtual void readDataAvailable(size_t len) noexcept=0
folly::AsyncTransportWrapper::ReadCallback * readCallback_
LogLevel min
Definition: LogLevel.cpp:30
virtual void getReadBuffer(void **bufReturn, size_t *lenReturn)=0
template<class C>
void HTTPUpstreamTest< C >::resumeWrites ( )
inline

Definition at line 150 of file HTTPUpstreamSessionTest.cpp.

150  {
151  pauseWrites_ = false;
152  for (auto cb: cbs_) {
153  handleWrite(cb);
154  }
155  cbs_.clear();
156  }
std::vector< folly::AsyncTransportWrapper::WriteCallback * > cbs_
void handleWrite(folly::AsyncTransportWrapper::WriteCallback *callback)
template<class C>
MockByteEventTracker* HTTPUpstreamTest< C >::setMockByteEventTracker ( )
inline

Definition at line 343 of file HTTPUpstreamSessionTest.cpp.

343  {
344  auto byteEventTracker = new MockByteEventTracker(nullptr);
346  std::unique_ptr<ByteEventTracker>(byteEventTracker));
347  EXPECT_CALL(*byteEventTracker, preSend(_, _, _))
348  .WillRepeatedly(Return(0));
349  EXPECT_CALL(*byteEventTracker, drainByteEvents())
350  .WillRepeatedly(Return(0));
351  EXPECT_CALL(*byteEventTracker, processByteEvents(_, _))
352  .WillRepeatedly(Invoke([]
353  (std::shared_ptr<ByteEventTracker> self,
354  uint64_t bytesWritten) {
355  return self->ByteEventTracker::processByteEvents(
356  self,
357  bytesWritten);
358  }));
359 
360  return byteEventTracker;
361  }
void setByteEventTracker(std::shared_ptr< ByteEventTracker > byteEventTracker)
HTTPUpstreamSession * httpSession_
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
template<class C>
void HTTPUpstreamTest< C >::SetUp ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 187 of file HTTPUpstreamSessionTest.cpp.

187  {
188  commonSetUp(makeClientCodec<typename C::Codec>(C::version));
189  }
ProtocolVersion version
void commonSetUp(unique_ptr< HTTPCodec > codec)
template<class C>
void HTTPUpstreamTest< C >::TearDown ( )
inlineoverridevirtual

Reimplemented from testing::Test.

Definition at line 306 of file HTTPUpstreamSessionTest.cpp.

306  {
308  for (auto& cb : cbs_) {
309  cb->writeErr(0, ex);
310  }
311  }
string UNKNOWN
Definition: tokenize.py:53
std::vector< folly::AsyncTransportWrapper::WriteCallback * > cbs_
template<class CodecPair >
void HTTPUpstreamTest< CodecPair >::testBasicRequest ( )

Definition at line 1028 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, and handler().

1028  {
1029  InSequence enforceOrder;
1030 
1031  auto handler = openTransaction();
1032  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1033  EXPECT_TRUE(msg->getIsChunked());
1034  EXPECT_FALSE(msg->getIsUpgraded());
1035  EXPECT_EQ(200, msg->getStatusCode());
1036  });
1037  handler->expectEOM();
1038  handler->expectDetachTransaction();
1039 
1040  handler->sendRequest();
1041  readAndLoop("HTTP/1.1 200 OK\r\n"
1042  "Transfer-Encoding: chunked\r\n\r\n"
1043  "0\r\n\r\n");
1044 
1046  CHECK_EQ(httpSession_->getNumOutgoingStreams(), 0);
1047 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< StrictMock< MockHTTPHandler > > openTransaction(bool expectStartPaused=false)
void handler(int, siginfo_t *, void *)
void readAndLoop(const std::string &input)
HTTPUpstreamSession * httpSession_
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
uint32_t getNumOutgoingStreams() const override
Definition: HTTPSession.h:80
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
bool supportsMoreTransactions() const
template<class CodecPair >
void HTTPUpstreamTest< CodecPair >::testBasicRequestHttp10 ( bool  keepalive)

Definition at line 1099 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, proxygen::getGetRequest(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_CONNECTION, proxygen::HTTPHeaders::set(), and proxygen::HTTPMessage::setHTTPVersion().

1099  {
1100  HTTPMessage req = getGetRequest();
1101  req.setHTTPVersion(1, 0);
1102  if (keepalive) {
1103  req.getHeaders().set(HTTP_HEADER_CONNECTION, "Keep-Alive");
1104  }
1105 
1106  InSequence enforceOrder;
1107 
1108  auto handler = openTransaction();
1109  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1110  EXPECT_EQ(200, msg->getStatusCode());
1111  EXPECT_EQ(keepalive ? "keep-alive" : "close",
1112  msg->getHeaders().getSingleOrEmpty(HTTP_HEADER_CONNECTION));
1113  });
1114  EXPECT_CALL(*handler, onBody(_));
1115  handler->expectEOM();
1116  handler->expectDetachTransaction();
1117 
1118  handler->sendRequest();
1119  if (keepalive) {
1120  readAndLoop("HTTP/1.0 200 OK\r\n"
1121  "Connection: keep-alive\r\n"
1122  "Content-length: 7\r\n\r\n"
1123  "content");
1124  } else {
1125  readAndLoop("HTTP/1.0 200 OK\r\n"
1126  "Connection: close\r\n"
1127  "Content-length: 7\r\n\r\n"
1128  "content");
1129  }
1130 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< StrictMock< MockHTTPHandler > > openTransaction(bool expectStartPaused=false)
void handler(int, siginfo_t *, void *)
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
void readAndLoop(const std::string &input)
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
void setHTTPVersion(uint8_t major, uint8_t minor)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
template<class CodecPair >
void HTTPUpstreamTest< CodecPair >::testSimpleUpgrade ( const std::string upgradeReqHeader,
const std::string upgradeRespHeader,
CodecProtocol  respCodecVersion 
)

Definition at line 1422 of file HTTPUpstreamSessionTest.cpp.

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

1425  {
1426  InSequence dummy;
1427  auto handler = openTransaction();
1429 
1430  httpSession_->setController(&controller);
1431  EXPECT_CALL(controller, onSessionCodecChange(httpSession_));
1432 
1434 
1435  HeaderIndexingStrategy testH2IndexingStrat;
1436  if (respCodecVersion == CodecProtocol::HTTP_2) {
1437  EXPECT_CALL(controller, getHeaderIndexingStrategy())
1438  .WillOnce(
1439  Return(&testH2IndexingStrat)
1440  );
1441  }
1442 
1443  handler->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1444  EXPECT_EQ(200, msg->getStatusCode());
1445  });
1446  handler->expectBody();
1447  handler->expectEOM();
1448  handler->expectDetachTransaction();
1449 
1450  auto txn = handler->txn_;
1451  HTTPMessage req = getUpgradeRequest(upgradeReqHeader);
1452  txn->sendHeaders(req);
1453  txn->sendEOM();
1454  eventBase_.loopOnce(); // force HTTP/1.1 writes
1455  writes_.move(); // clear them out
1456  readAndLoop(folly::to<string>("HTTP/1.1 101 Switching Protocols\r\n"
1457  "Upgrade: ", upgradeRespHeader, "\r\n"
1458  "\r\n"));
1459 
1460  if (respCodecVersion == CodecProtocol::HTTP_2) {
1461  const HTTP2Codec* codec = dynamic_cast<const HTTP2Codec*>(
1462  &txn->getTransport().getCodec());
1463  ASSERT_NE(codec, nullptr);
1464  EXPECT_EQ(codec->getHeaderIndexingStrategy(), &testH2IndexingStrat);
1465  }
1466 
1467  readAndLoop(getResponseBuf(respCodecVersion, txn->getID(), 200, 100).get());
1468 
1470  httpSession_->destroy();
1471 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
CodecFactory codec
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: HTTP2Codec.h:174
std::unique_ptr< StrictMock< MockHTTPHandler > > openTransaction(bool expectStartPaused=false)
void handler(int, siginfo_t *, void *)
uint32_t getMaxConcurrentOutgoingStreams() const
void readAndLoop(const std::string &input)
HTTPUpstreamSession * httpSession_
bool loopOnce(int flags=0)
Definition: EventBase.cpp:271
void dummy()
void setController(HTTPSessionController *controller)
#define EXPECT_CALL(obj, call)
#define ASSERT_NE(val1, val2)
Definition: gtest.h:1960
HTTPMessage getUpgradeRequest(const std::string &upgradeHeader, HTTPMethod method, uint32_t bodyLen)
Definition: TestUtils.cpp:161
internal::ReturnAction< R > Return(R value)

Member Data Documentation

template<class C>
std::vector<folly::AsyncTransportWrapper::WriteCallback*> HTTPUpstreamTest< C >::cbs_
protected

Definition at line 382 of file HTTPUpstreamSessionTest.cpp.

template<class C>
EventBase HTTPUpstreamTest< C >::eventBase_
protected

Definition at line 370 of file HTTPUpstreamSessionTest.cpp.

template<class C>
EventBase* HTTPUpstreamTest< C >::eventBasePtr_ {&eventBase_}
protected

Definition at line 371 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::failWrites_ {false}
protected

Definition at line 383 of file HTTPUpstreamSessionTest.cpp.

template<class C>
std::vector<int64_t> HTTPUpstreamTest< C >::flowControl_
protected

Definition at line 376 of file HTTPUpstreamSessionTest.cpp.

template<class C>
HTTPUpstreamSession* HTTPUpstreamTest< C >::httpSession_ {nullptr}
protected

Definition at line 380 of file HTTPUpstreamSessionTest.cpp.

template<class C>
SocketAddress HTTPUpstreamTest< C >::localAddr_ {"127.0.0.1", 80}
protected

Definition at line 378 of file HTTPUpstreamSessionTest.cpp.

template<class C>
wangle::TransportInfo HTTPUpstreamTest< C >::mockTransportInfo_
protected

Definition at line 377 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::pauseWrites_ {false}
protected

Definition at line 384 of file HTTPUpstreamSessionTest.cpp.

template<class C>
SocketAddress HTTPUpstreamTest< C >::peerAddr_ {"127.0.0.1", 12345}
protected

Definition at line 379 of file HTTPUpstreamSessionTest.cpp.

template<class C>
folly::AsyncTransportWrapper::ReadCallback* HTTPUpstreamTest< C >::readCallback_ {nullptr}
protected

Definition at line 373 of file HTTPUpstreamSessionTest.cpp.

template<class C>
folly::AsyncTransport::ReplaySafetyCallback* HTTPUpstreamTest< C >::replaySafetyCallback_ {nullptr}
protected

Definition at line 374 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::sessionCreated_ {false}
protected

Definition at line 364 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::sessionDestroyed_ {false}
protected

Definition at line 365 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::transactionsFull_ {false}
protected

Definition at line 367 of file HTTPUpstreamSessionTest.cpp.

template<class C>
folly::HHWheelTimer::UniquePtr HTTPUpstreamTest< C >::transactionTimeouts_
protected

Definition at line 375 of file HTTPUpstreamSessionTest.cpp.

template<class C>
MockAsyncTransport* HTTPUpstreamTest< C >::transport_
protected

Definition at line 372 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::transportGood_ {true}
protected

Definition at line 368 of file HTTPUpstreamSessionTest.cpp.

template<class C>
bool HTTPUpstreamTest< C >::writeInLoop_ {false}
protected

Definition at line 385 of file HTTPUpstreamSessionTest.cpp.

template<class C>
IOBufQueue HTTPUpstreamTest< C >::writes_ {IOBufQueue::cacheChainLength()}
protected

Definition at line 381 of file HTTPUpstreamSessionTest.cpp.


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