proxygen
HTTPUpstreamSessionTest.cpp File Reference

Go to the source code of this file.

Classes

class  TestPriorityMapBuilder
 
class  TestPriorityAdapter
 
class  HTTPUpstreamTest< C >
 
class  TimeoutableHTTPUpstreamTest< C >
 
class  HTTP2UpstreamSessionWithVirtualNodesTest
 
class  HTTP2UpstreamSessionWithPriorityTree
 
class  HTTPUpstreamRecvStreamTest
 
class  NoFlushUpstreamSessionTest
 
class  MockHTTPUpstreamTest
 
class  MockHTTP2UpstreamTest
 
class  TestAbortPost< stage >
 

Typedefs

using HTTPUpstreamSessionTest = HTTPUpstreamTest< HTTP1xCodecPair >
 
using SPDY3UpstreamSessionTest = HTTPUpstreamTest< SPDY3CodecPair >
 
using HTTP2UpstreamSessionTest = HTTPUpstreamTest< HTTP2CodecPair >
 
using HTTPUpstreamTimeoutTest = TimeoutableHTTPUpstreamTest< HTTP1xCodecPair >
 
typedef TestAbortPost< 0 > TestAbortPost0
 
typedef TestAbortPost< 1 > TestAbortPost1
 
typedef TestAbortPost< 2 > TestAbortPost2
 
typedef TestAbortPost< 3 > TestAbortPost3
 
typedef TestAbortPost< 4 > TestAbortPost4
 
typedef TestAbortPost< 5 > TestAbortPost5
 
using AllTypes = ::testing::Types< HTTP1xCodecPair, SPDY3CodecPair >
 

Functions

 TYPED_TEST_CASE_P (HTTPUpstreamTest)
 
 TEST_F (SPDY3UpstreamSessionTest, ServerPush)
 
 TEST_F (SPDY3UpstreamSessionTest, IngressGoawayAbortUncreatedStreams)
 
 TEST_F (SPDY3UpstreamSessionTest, IngressGoawaySessionError)
 
 TEST_F (SPDY3UpstreamSessionTest, TestUnderLimitOnWriteError)
 
 TEST_F (SPDY3UpstreamSessionTest, TestOverlimitResume)
 
 TEST_F (HTTP2UpstreamSessionTest, TestPriority)
 
 TEST_F (HTTP2UpstreamSessionTest, TestSettingsAck)
 
 TEST_F (HTTP2UpstreamSessionTest, TestSettingsInfoCallbacks)
 
 TEST_F (HTTP2UpstreamSessionTest, TestSetControllerInitHeaderIndexingStrat)
 
 TEST_F (HTTP2UpstreamSessionTest, ExheaderFromServer)
 
 TEST_F (HTTP2UpstreamSessionTest, InvalidControlStream)
 
 TEST_F (HTTP2UpstreamSessionWithVirtualNodesTest, VirtualNodes)
 
 TEST_F (HTTP2UpstreamSessionWithPriorityTree, PriorityTree)
 
 TYPED_TEST_P (HTTPUpstreamTest, ImmediateEof)
 
 TEST_F (HTTPUpstreamSessionTest, BasicRequest)
 
 TEST_F (HTTPUpstreamSessionTest, TwoRequests)
 
 TEST_F (HTTPUpstreamSessionTest, 10Requests)
 
 TEST_F (HTTPUpstreamSessionTest, TestFirstHeaderByteEventTracker)
 
 TEST_F (HTTPUpstreamSessionTest, Http10Keepalive)
 
 TEST_F (HTTPUpstreamSessionTest, BasicTrailers)
 
 TEST_F (HTTP2UpstreamSessionTest, BasicTrailers)
 
 TEST_F (HTTP2UpstreamSessionTest, HeadersThenBodyThenHeaders)
 
 TEST_F (HTTPUpstreamSessionTest, TwoRequestsWithPause)
 
 TEST_F (HTTPUpstreamTimeoutTest, WriteTimeoutAfterResponse)
 
 TEST_F (HTTPUpstreamSessionTest, SetTransactionTimeout)
 
 TEST_F (HTTPUpstreamSessionTest, ReadTimeout)
 
 TEST_F (HTTPUpstreamSessionTest, 100ContinueKeepalive)
 
 TEST_F (HTTPUpstreamSessionTest, 417Keepalive)
 
 TEST_F (HTTPUpstreamSessionTest, 101Upgrade)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradeNativeH2)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradeNativeUnknown)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradeNativeWhitespace)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradeNativeJunk)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgrade101Unexpected)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgrade101MissingUpgrade)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgrade101BogusHeader)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradePost100)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradePost100Http2)
 
 TEST_F (HTTPUpstreamSessionTest, HttpUpgradeOnTxn2)
 
 TEST_F (HTTPUpstreamRecvStreamTest, UpgradeFlowControl)
 
 TEST_F (NoFlushUpstreamSessionTest, SessionPausedStartPaused)
 
 TEST_F (NoFlushUpstreamSessionTest, DeleteTxnOnUnpause)
 
 TEST_F (HTTP2UpstreamSessionTest, ServerPush)
 
 TEST_F (MockHTTP2UpstreamTest, ParseErrorNoTxn)
 
 TEST_F (MockHTTPUpstreamTest, 0MaxOutgoingTxns)
 
 TEST_F (MockHTTPUpstreamTest, OutgoingTxnSettings)
 
 TEST_F (MockHTTPUpstreamTest, IngressGoawayDrain)
 
 TEST_F (MockHTTPUpstreamTest, Goaway)
 
 TEST_F (MockHTTPUpstreamTest, GoawayPreHeaders)
 
 TEST_F (MockHTTPUpstreamTest, NoWindowUpdateOnDrain)
 
 TEST_F (MockHTTPUpstreamTest, GetWithBody)
 
 TEST_F (MockHTTPUpstreamTest, HeaderWithEom)
 
 TEST_F (TestAbortPost1, Test)
 
 TEST_F (TestAbortPost2, Test)
 
 TEST_F (TestAbortPost3, Test)
 
 TEST_F (TestAbortPost4, Test)
 
 TEST_F (TestAbortPost5, Test)
 
 TEST_F (MockHTTPUpstreamTest, AbortUpgrade)
 
 TEST_F (MockHTTPUpstreamTest, DrainBeforeSendHeaders)
 
 TEST_F (MockHTTP2UpstreamTest, ReceiveDoubleGoaway)
 
 TEST_F (MockHTTP2UpstreamTest, ServerPushInvalidAssoc)
 
 TEST_F (MockHTTP2UpstreamTest, ServerPushAfterFin)
 
 TEST_F (MockHTTP2UpstreamTest, ServerPushHandlerInstallFail)
 
 TEST_F (MockHTTP2UpstreamTest, ServerPushUnhandledAssoc)
 
 TEST_F (MockHTTPUpstreamTest, HeadersThenBodyThenHeaders)
 
 TEST_F (MockHTTP2UpstreamTest, DelayUpstreamWindowUpdate)
 
 TEST_F (MockHTTPUpstreamTest, ForceShutdownInSetTransaction)
 
 TEST_F (HTTP2UpstreamSessionTest, TestReplaySafetyCallback)
 
 TEST_F (HTTP2UpstreamSessionTest, TestAlreadyReplaySafe)
 
 TEST_F (HTTP2UpstreamSessionTest, TestChainedBufIngress)
 
 TEST_F (HTTP2UpstreamSessionTest, AttachDetach)
 
 REGISTER_TYPED_TEST_CASE_P (HTTPUpstreamTest, ImmediateEof)
 
 INSTANTIATE_TYPED_TEST_CASE_P (AllTypesPrefix, HTTPUpstreamTest, AllTypes)
 

Typedef Documentation

using AllTypes = ::testing::Types<HTTP1xCodecPair, SPDY3CodecPair>

Definition at line 2696 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2258 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2259 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2260 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2261 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2262 of file HTTPUpstreamSessionTest.cpp.

Definition at line 2263 of file HTTPUpstreamSessionTest.cpp.

Function Documentation

INSTANTIATE_TYPED_TEST_CASE_P ( AllTypesPrefix  ,
HTTPUpstreamTest  ,
AllTypes   
)
REGISTER_TYPED_TEST_CASE_P ( HTTPUpstreamTest  ,
ImmediateEof   
)

Referenced by TEST_F().

TEST_F ( SPDY3UpstreamSessionTest  ,
ServerPush   
)

Definition at line 407 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::SPDYCodec::generateBody(), proxygen::SPDYCodec::generateHeader(), proxygen::SPDYCodec::generatePushPromise(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_HOST, testing::Invoke(), folly::IOBuf::length(), makeBuf(), folly::IOBufQueue::move(), folly::gen::move, gmock_output_test::output, proxygen::HTTPHeaders::set(), proxygen::HTTPTransaction::setHandler(), proxygen::HTTPMessage::setStatusCode(), proxygen::HTTPMessage::setStatusMessage(), and proxygen::HTTPMessage::setURL().

407  {
408  SPDYCodec egressCodec(TransportDirection::DOWNSTREAM,
409  SPDYVersion::SPDY3);
411 
412  HTTPMessage push;
413  push.getHeaders().set("HOST", "www.foo.com");
414  push.setURL("https://www.foo.com/");
415  egressCodec.generatePushPromise(output, 2, push, 1, false, nullptr);
416  auto buf = makeBuf(100);
417  egressCodec.generateBody(output, 2, std::move(buf), HTTPCodec::NoPadding,
418  true /* eom */);
419 
420  HTTPMessage resp;
421  resp.setStatusCode(200);
422  resp.setStatusMessage("Ohai");
423  egressCodec.generateHeader(output, 1, resp, false, nullptr);
424  buf = makeBuf(100);
425  egressCodec.generateBody(output, 1, std::move(buf), HTTPCodec::NoPadding,
426  true /* eom */);
427 
428  std::unique_ptr<folly::IOBuf> input = output.move();
429  input->coalesce();
430 
431  MockHTTPHandler pushHandler;
432 
433  InSequence enforceOrder;
434 
435  auto handler = openTransaction();
436  EXPECT_CALL(*handler, onPushedTransaction(_))
437  .WillOnce(Invoke([&pushHandler] (HTTPTransaction* pushTxn) {
438  pushTxn->setHandler(&pushHandler);
439  }));
440  EXPECT_CALL(pushHandler, setTransaction(_));
441  EXPECT_CALL(pushHandler, onHeadersComplete(_))
442  .WillOnce(Invoke([&] (std::shared_ptr<HTTPMessage> msg) {
443  EXPECT_EQ(httpSession_->getNumIncomingStreams(), 1);
444  EXPECT_TRUE(msg->getIsChunked());
445  EXPECT_FALSE(msg->getIsUpgraded());
446  EXPECT_EQ(msg->getPath(), "/");
447  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty(HTTP_HEADER_HOST),
448  "www.foo.com");
449  }));
450  EXPECT_CALL(pushHandler, onBody(_));
451  EXPECT_CALL(pushHandler, onEOM());
452  EXPECT_CALL(pushHandler, detachTransaction());
453 
454  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
455  EXPECT_FALSE(msg->getIsUpgraded());
456  EXPECT_EQ(200, msg->getStatusCode());
457  });
458  EXPECT_CALL(*handler, onBody(_));
459  handler->expectEOM();
460  handler->expectDetachTransaction();
461 
462  handler->sendRequest();
463  readAndLoop(input->data(), input->length());
464 
465  EXPECT_EQ(httpSession_->getNumIncomingStreams(), 0);
466  httpSession_->destroy();
467 }
virtual void setHandler(Handler *handler)
ByteRange coalesce()
Definition: IOBuf.h:1095
void setStatusMessage(T &&msg)
Definition: HTTPMessage.h:242
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint8_t * data() const
Definition: IOBuf.h:499
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
ParseURL setURL(T &&url)
Definition: HTTPMessage.h:183
static Options cacheChainLength()
Definition: IOBufQueue.h:83
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::size_t length() const
Definition: IOBuf.h:533
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void setStatusCode(uint16_t status)
TEST_F ( SPDY3UpstreamSessionTest  ,
IngressGoawayAbortUncreatedStreams   
)

Definition at line 469 of file HTTPUpstreamSessionTest.cpp.

References ASSERT_EQ, folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_EQ, EXPECT_TRUE, proxygen::SPDYCodec::generateGoaway(), proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorStreamUnacknowledged, folly::IOBuf::length(), string, and proxygen::Exception::what().

469  {
470  // Tests whether the session aborts the streams which are not created
471  // at the remote end.
472 
473  // Create SPDY buf for GOAWAY with last good stream as 0 (no streams created)
474  SPDYCodec egressCodec(TransportDirection::DOWNSTREAM,
475  SPDYVersion::SPDY3);
476  folly::IOBufQueue respBuf{IOBufQueue::cacheChainLength()};
477  egressCodec.generateGoaway(respBuf, 0, ErrorCode::NO_ERROR);
478  std::unique_ptr<folly::IOBuf> goawayFrame = respBuf.move();
479  goawayFrame->coalesce();
480 
481  InSequence enforceOrder;
482 
483  auto handler = openTransaction();
484  handler->expectGoaway();
485  handler->expectError([&] (const HTTPException& err) {
488  ASSERT_EQ(
489  folly::to<std::string>("StreamUnacknowledged on transaction id: ",
490  handler->txn_->getID()),
491  std::string(err.what()));
492  });
493  handler->expectDetachTransaction([this] {
494  // Make sure the session can't create any more transactions.
495  MockHTTPHandler handler2;
496  EXPECT_EQ(httpSession_->newTransaction(&handler2), nullptr);
497  });
498 
499  // Send the GET request
500  handler->sendRequest();
501 
502  // Receive GOAWAY frame while waiting for SYN_REPLY
503  readAndLoop(goawayFrame->data(), goawayFrame->length());
504 
505  // Session will delete itself after the abort
506 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
ByteRange coalesce()
Definition: IOBuf.h:1095
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const uint8_t * data() const
Definition: IOBuf.h:499
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
void handler(int, siginfo_t *, void *)
std::size_t length() const
Definition: IOBuf.h:533
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( SPDY3UpstreamSessionTest  ,
IngressGoawaySessionError   
)

Definition at line 508 of file HTTPUpstreamSessionTest.cpp.

References ASSERT_EQ, folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_EQ, EXPECT_TRUE, proxygen::SPDYCodec::generateGoaway(), proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorStreamUnacknowledged, folly::IOBuf::length(), string, and proxygen::Exception::what().

508  {
509  // Tests whether the session aborts the streams which are not created
510  // at the remote end which have error codes.
511 
512  // Create SPDY buf for GOAWAY with last good stream as 0 (no streams created)
513  SPDYCodec egressCodec(TransportDirection::DOWNSTREAM,
514  SPDYVersion::SPDY3);
515  folly::IOBufQueue respBuf{IOBufQueue::cacheChainLength()};
516  egressCodec.generateGoaway(respBuf, 0, ErrorCode::PROTOCOL_ERROR);
517  std::unique_ptr<folly::IOBuf> goawayFrame = respBuf.move();
518  goawayFrame->coalesce();
519 
520  InSequence enforceOrder;
521 
522  auto handler = openTransaction();
523  handler->expectGoaway();
524  handler->expectError([&] (const HTTPException& err) {
527  ASSERT_EQ(
528  folly::to<std::string>("StreamUnacknowledged on transaction id: ",
529  handler->txn_->getID(),
530  " with codec error: PROTOCOL_ERROR"),
531  std::string(err.what()));
532  });
533  handler->expectDetachTransaction([this] {
534  // Make sure the session can't create any more transactions.
535  MockHTTPHandler handler2;
536  EXPECT_EQ(httpSession_->newTransaction(&handler2), nullptr);
537  });
538 
539  // Send the GET request
540  handler->sendRequest();
541 
542  // Receive GOAWAY frame while waiting for SYN_REPLY
543  readAndLoop(goawayFrame->data(), goawayFrame->length());
544 
545  // Session will delete itself after the abort
546 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
ByteRange coalesce()
Definition: IOBuf.h:1095
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const uint8_t * data() const
Definition: IOBuf.h:499
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
void handler(int, siginfo_t *, void *)
std::size_t length() const
Definition: IOBuf.h:533
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( SPDY3UpstreamSessionTest  ,
TestUnderLimitOnWriteError   
)

Definition at line 548 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, proxygen::getPostRequest(), handler(), and makeBuf().

548  {
549  InSequence enforceOrder;
550  auto handler = openTransaction();
551 
552  auto req = getPostRequest();
553  handler->txn_->sendHeaders(req);
554  // pause writes
555  pauseWrites_ = true;
556  handler->expectEgressPaused();
557 
558  // send body
559  handler->txn_->sendBody(makeBuf(70000));
560  eventBase_.loopOnce();
561 
562  // but no expectEgressResumed
563  handler->expectError();
564  handler->expectDetachTransaction();
565  failWrites_ = true;
566  resumeWrites();
567 
568  this->eventBase_.loop();
569  EXPECT_EQ(this->sessionDestroyed_, true);
570 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
TEST_F ( SPDY3UpstreamSessionTest  ,
TestOverlimitResume   
)

Definition at line 572 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, proxygen::getPostRequest(), and makeBuf().

572  {
573  InSequence enforceOrder;
574  auto handler1 = openTransaction();
575  auto handler2 = openTransaction();
576 
577  // Disable stream flow control for this test
578  handler1->txn_->onIngressWindowUpdate(80000);
579  handler2->txn_->onIngressWindowUpdate(80000);
580 
581  auto req = getPostRequest();
582  handler1->txn_->sendHeaders(req);
583  handler2->txn_->sendHeaders(req);
584  // pause writes
585  pauseWrites_ = true;
586  handler1->expectEgressPaused();
587  handler2->expectEgressPaused();
588 
589  // send body
590  handler1->txn_->sendBody(makeBuf(70000));
591  handler2->txn_->sendBody(makeBuf(70000));
592  eventBase_.loopOnce();
593 
594  // when this handler is resumed, re-pause the pipe
595  handler1->expectEgressResumed([&] {
596  handler1->txn_->sendBody(makeBuf(70000));
597  });
598  // handler2 will get a shot
599  handler2->expectEgressResumed();
600 
601  // both handlers will be paused
602  handler1->expectEgressPaused();
603  handler2->expectEgressPaused();
604  resumeWrites();
605 
606  // They both get resumed
607  handler1->expectEgressResumed([&] { handler1->txn_->sendEOM(); });
608  handler2->expectEgressResumed([&] { handler2->txn_->sendEOM(); });
609 
610  this->eventBase_.loop();
611 
612  // less than graceful shutdown
613  handler1->expectError();
614  handler1->expectDetachTransaction();
615  handler2->expectError();
616  handler2->expectDetachTransaction();
617 
618  httpSession_->dropConnection();
619  EXPECT_EQ(this->sessionDestroyed_, true);
620 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
TEST_F ( HTTP2UpstreamSessionTest  ,
TestPriority   
)

Definition at line 622 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, proxygen::getGetRequest(), testing::Invoke(), makeServerCodec(), and uint32_t.

622  {
623  InSequence enforceOrder;
624  // virtual priority node with pri=8
625  auto priGroupID = httpSession_->sendPriority({0, false, 7});
626  auto handler1 = openTransaction();
627  auto handler2 = openTransaction();
628 
629  auto req = getGetRequest();
630  // send request with maximal weight
631  req.setHTTP2Priority(HTTPMessage::HTTPPriority(0, false, 255));
632  handler1->sendRequest(req);
633  handler2->sendRequest(req);
634 
635  auto id = handler1->txn_->getID();
636  auto id2 = handler2->txn_->getID();
637 
638  // Insert depth is 1, only root node has depth 0
639  EXPECT_EQ(std::get<0>(handler1->txn_->getPrioritySummary()), 1);
640  EXPECT_EQ(handler1->txn_->getPriorityFallback(), false);
641 
642  // update handler to be in the pri-group
643  handler1->txn_->updateAndSendPriority(
644  http2::PriorityUpdate{(uint32_t)priGroupID, false, 15});
645  handler2->txn_->updateAndSendPriority(
646  http2::PriorityUpdate{(uint32_t)priGroupID + 254, false, 15});
647 
648  // Change pri-group weight to max
649  httpSession_->sendPriority(priGroupID, http2::PriorityUpdate{0, false, 255});
650  eventBase_.loop();
651 
652  auto serverCodec = makeServerCodec();
654  serverCodec->setCallback(&callbacks);
655  EXPECT_CALL(callbacks, onPriority(priGroupID,
656  HTTPMessage::HTTPPriority(0, false, 7)));
657  EXPECT_CALL(callbacks, onHeadersComplete(id, _))
658  .WillOnce(Invoke([&] (HTTPCodec::StreamID,
659  std::shared_ptr<HTTPMessage> msg) {
660  EXPECT_EQ(*(msg->getHTTP2Priority()),
661  HTTPMessage::HTTPPriority(0, false, 255));
662  }));
663  EXPECT_CALL(callbacks, onHeadersComplete(id2, _))
664  .WillOnce(Invoke([&] (HTTPCodec::StreamID,
665  std::shared_ptr<HTTPMessage> msg) {
666  EXPECT_EQ(*(msg->getHTTP2Priority()),
667  HTTPMessage::HTTPPriority(0, false, 255));
668  }));
669  EXPECT_CALL(callbacks,
670  onPriority(
671  id, HTTPMessage::HTTPPriority(priGroupID, false, 15)));
672  EXPECT_CALL(callbacks,
673  onPriority(
674  id2, HTTPMessage::HTTPPriority(priGroupID + 254, false, 15)));
675  EXPECT_EQ(handler1->txn_->getPriorityFallback(), false);
676  EXPECT_EQ(handler2->txn_->getPriorityFallback(), false);
677 
678  EXPECT_EQ(std::get<1>(handler1->txn_->getPrioritySummary()), 2);
679  // created virtual parent node
680  EXPECT_EQ(std::get<1>(handler2->txn_->getPrioritySummary()), 2);
681  EXPECT_CALL(callbacks,
682  onPriority(priGroupID, HTTPMessage::HTTPPriority(0, false, 255)));
683  parseOutput(*serverCodec);
684  eventBase_.loop();
685 
686  handler1->expectError();
687  handler1->expectDetachTransaction();
688  handler2->expectError();
689  handler2->expectDetachTransaction();
690  httpSession_->dropConnection();
691  eventBase_.loop();
692  EXPECT_EQ(sessionDestroyed_, true);
693 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::tuple< uint32_t, bool, uint8_t > HTTPPriority
Definition: HTTPMessage.h:592
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionTest  ,
TestSettingsAck   
)

Definition at line 695 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), EXPECT_CALL, EXPECT_EQ, and makeServerCodec().

695  {
696  auto serverCodec = makeServerCodec();
697  folly::IOBufQueue buf{IOBufQueue::cacheChainLength()};
698  serverCodec->generateSettings(buf);
699  auto settingsFrame = buf.move();
700  settingsFrame->coalesce();
701 
702  InSequence enforceOrder;
703 
705  serverCodec->setCallback(&callbacks);
706  EXPECT_CALL(callbacks, onSettings(_));
707  EXPECT_CALL(callbacks, onSettingsAck());
708 
709  readAndLoop(settingsFrame.get());
710  parseOutput(*serverCodec);
711  httpSession_->dropConnection();
712  EXPECT_EQ(sessionDestroyed_, true);
713 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionTest  ,
TestSettingsInfoCallbacks   
)

Definition at line 715 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), EXPECT_CALL, and makeServerCodec().

715  {
716  auto serverCodec = makeServerCodec();
717 
718  folly::IOBufQueue settingsBuf{IOBufQueue::cacheChainLength()};
719  serverCodec->generateSettings(settingsBuf);
720  auto settingsFrame = settingsBuf.move();
721 
722  folly::IOBufQueue settingsAckBuf{IOBufQueue::cacheChainLength()};
723  serverCodec->generateSettingsAck(settingsAckBuf);
724  auto settingsAckFrame = settingsAckBuf.move();
725 
727  httpSession_->setInfoCallback(&infoCb);
728 
729  EXPECT_CALL(infoCb, onRead(_, _)).Times(2);
730  EXPECT_CALL(infoCb, onWrite(_, _)).Times(1);
731  EXPECT_CALL(infoCb, onDestroy(_)).Times(1);
732 
733  EXPECT_CALL(infoCb, onSettings(_, _)).Times(1);
734  EXPECT_CALL(infoCb, onSettingsAck(_)).Times(1);
735 
736  InSequence enforceOrder;
737 
738  readAndLoop(settingsFrame.get());
739  readAndLoop(settingsAckFrame.get());
740 
741  httpSession_->destroy();
742 }
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionTest  ,
TestSetControllerInitHeaderIndexingStrat   
)

Definition at line 744 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, proxygen::HTTP2Codec::getHeaderIndexingStrategy(), handler(), and testing::Return().

744  {
745  StrictMock<MockUpstreamController> mockController;
746  HeaderIndexingStrategy testH2IndexingStrat;
747  EXPECT_CALL(mockController, getHeaderIndexingStrategy())
748  .WillOnce(
749  Return(&testH2IndexingStrat)
750  );
751 
752  httpSession_->setController(&mockController);
753 
754  auto handler = openTransaction();
755  handler->expectDetachTransaction();
756 
757  const HTTP2Codec* h2Codec = static_cast<const HTTP2Codec*>(
758  &handler->txn_->getTransport().getCodec());
759  EXPECT_EQ(h2Codec->getHeaderIndexingStrategy(), &testH2IndexingStrat);
760 
761  handler->txn_->sendAbort();
762  eventBase_.loop();
763 
764  EXPECT_CALL(mockController, detachSession(_));
765  httpSession_->destroy();
766 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: HTTP2Codec.h:174
void handler(int, siginfo_t *, void *)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
TEST_F ( HTTP2UpstreamSessionTest  ,
ExheaderFromServer   
)

Definition at line 777 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), EXPECT_CALL, EXPECT_EQ, proxygen::getGetRequest(), proxygen::getResponse(), testing::Invoke(), makeServerCodec(), and proxygen::HTTPTransaction::setHandler().

777  {
778  folly::IOBufQueue queue{IOBufQueue::cacheChainLength()};
779 
780  // generate enable_ex_headers setting
781  auto serverCodec = makeServerCodec();
782  enableExHeader(serverCodec.get());
783  serverCodec->generateSettings(queue);
784  // generate the response for control stream, but EOM
785  auto cStreamId = HTTPCodec::StreamID(1);
786  serverCodec->generateHeader(queue, cStreamId, getResponse(200, 0),
787  false, nullptr);
788  // generate a request from server, encapsulated in EX_HEADERS frame
789  serverCodec->generateExHeader(queue, 2, getGetRequest("/messaging"),
790  HTTPCodec::ExAttributes(cStreamId, false),
791  true, nullptr);
792  serverCodec->generateEOM(queue, 1);
793 
794  auto cHandler = openTransaction();
795  cHandler->sendRequest(getGetRequest("/cc"));
796 
797  NiceMock<MockHTTPHandler> pubHandler;
798  InSequence handlerSequence;
799  cHandler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
800  EXPECT_EQ(200, msg->getStatusCode());
801  });
802 
803  EXPECT_CALL(*cHandler, onExTransaction(_))
804  .WillOnce(Invoke([&pubHandler] (HTTPTransaction* pubTxn) {
805  pubTxn->setHandler(&pubHandler);
806  pubHandler.txn_ = pubTxn;
807  }));
808  pubHandler.expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
809  EXPECT_EQ(msg->getPath(), "/messaging");
810  });
811  pubHandler.expectEOM([&] () {
812  pubHandler.txn_->sendAbort();
813  });
814  pubHandler.expectDetachTransaction();
815 
816  cHandler->expectEOM();
817  cHandler->expectDetachTransaction();
818 
819  auto buf = queue.move();
820  buf->coalesce();
821  readAndLoop(buf.get());
822 
823  httpSession_->destroy();
824 }
virtual void setHandler(Handler *handler)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
HTTPMessage getResponse(uint32_t code, uint32_t bodyLen)
Definition: TestUtils.cpp:137
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionTest  ,
InvalidControlStream   
)

Definition at line 826 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), EXPECT_CALL, EXPECT_EQ, proxygen::getGetRequest(), proxygen::getResponse(), and makeServerCodec().

826  {
827  folly::IOBufQueue queue{IOBufQueue::cacheChainLength()};
828 
829  // generate enable_ex_headers setting
830  auto serverCodec = makeServerCodec();
831  enableExHeader(serverCodec.get());
832  serverCodec->generateSettings(queue);
833  // generate the response for control stream, but EOM
834  auto cStreamId = HTTPCodec::StreamID(1);
835  serverCodec->generateHeader(queue, cStreamId, getResponse(200, 0),
836  false, nullptr);
837  // generate a EX_HEADERS frame with non-existing control stream
838  serverCodec->generateExHeader(queue, 2, getGetRequest("/messaging"),
839  HTTPCodec::ExAttributes(cStreamId + 2, false),
840  true, nullptr);
841  serverCodec->generateEOM(queue, 1);
842 
843  auto cHandler = openTransaction();
844  cHandler->sendRequest(getGetRequest("/cc"));
845 
846  InSequence handlerSequence;
847  cHandler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
848  EXPECT_EQ(200, msg->getStatusCode());
849  });
850  EXPECT_CALL(*cHandler, onExTransaction(_)).Times(0);
851  cHandler->expectEOM();
852  cHandler->expectDetachTransaction();
853 
854  auto buf = queue.move();
855  buf->coalesce();
856  readAndLoop(buf.get());
857 
858  httpSession_->destroy();
859 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
HTTPMessage getResponse(uint32_t code, uint32_t bodyLen)
Definition: TestUtils.cpp:137
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionWithVirtualNodesTest  ,
VirtualNodes   
)

Definition at line 928 of file HTTPUpstreamSessionTest.cpp.

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

928  {
929  InSequence enforceOrder;
930 
931  HTTPCodec::StreamID deps[] = {11, 13, 15};
932  EXPECT_CALL(*codecPtr_, addPriorityNodes(_, _, _))
933  .Times(1)
934  .WillOnce(Invoke([&] (
937  uint8_t maxLevel) {
938  for (size_t i = 0; i < maxLevel; i++) {
939  dependencies.push_back(deps[i]);
940  }
941  return 123;
942  }));
943  httpSession_->startNow();
944 
945  EXPECT_EQ(level_, dependencies.size());
947  handler.expectTransaction();
948  auto txn = httpSession_->newTransaction(&handler);
949 
950  EXPECT_CALL(*codecPtr_, mapPriorityToDependency(_))
951  .Times(1)
952  .WillOnce(Invoke([&] (uint8_t priority) {
953  return dependencies[priority];
954  }));
955  txn->updateAndSendPriority(0);
956 
957  handler.expectError();
958  handler.expectDetachTransaction();
959  httpSession_->dropConnection();
960 
961  eventBase_.loop();
962 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
TEST_F ( HTTP2UpstreamSessionWithPriorityTree  ,
PriorityTree   
)

Definition at line 972 of file HTTPUpstreamSessionTest.cpp.

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

972  {
973  InSequence enforceOrder;
974 
975  std::array<HTTPCodec::StreamID, 3> deps = { {11, 13, 15} };
976  EXPECT_CALL(*codecPtr_, addPriorityNodes(_, _, _))
977  .Times(0)
978  .WillOnce(Invoke([&] (
981  uint8_t maxLevel) {
982  for (size_t i = 0; i < maxLevel; i++) {
983  dependencies.push_back(deps[i]);
984  }
985  return 123;
986  }));
987  httpSession_->startNow();
988 
989  // It should have built the virtual streams from the tree but not the old
990  // priority levels.
991  EXPECT_EQ(dependencies.size(), 0);
993  *httpSession_->getHTTPPriority(builder_->hiPriLevel_);
994  EXPECT_EQ(std::get<2>(hiPri), builder_->hiPriWeight_);
996  *httpSession_->getHTTPPriority(builder_->loPriLevel_);
997  EXPECT_EQ(std::get<2>(loPri), builder_->loPriWeight_);
998 
999  for (size_t level = 0; level < 256; ++level) {
1000  if (level == builder_->hiPriLevel_) {
1001  continue;
1002  }
1003  HTTPMessage::HTTPPriority pri = *httpSession_->getHTTPPriority(level);
1004  EXPECT_EQ(pri, loPri);
1005  }
1006 
1008  handler.expectTransaction();
1009  auto txn = httpSession_->newTransaction(&handler);
1010 
1011  txn->updateAndSendPriority(0);
1012 
1013  handler.expectError();
1014  handler.expectDetachTransaction();
1015  httpSession_->dropConnection();
1016 
1017  eventBase_.loop();
1018 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::tuple< uint32_t, bool, uint8_t > HTTPPriority
Definition: HTTPMessage.h:592
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( HTTPUpstreamSessionTest  ,
BasicRequest   
)

Definition at line 1049 of file HTTPUpstreamSessionTest.cpp.

1049  {
1050  testBasicRequest();
1051  httpSession_->destroy();
1052 }
TEST_F ( HTTPUpstreamSessionTest  ,
TwoRequests   
)

Definition at line 1054 of file HTTPUpstreamSessionTest.cpp.

1054  {
1055  testBasicRequest();
1056  testBasicRequest();
1057  httpSession_->destroy();
1058 }
TEST_F ( HTTPUpstreamSessionTest  ,
10Requests   
)

Definition at line 1060 of file HTTPUpstreamSessionTest.cpp.

References i, and uint16_t.

1060  {
1061  for (uint16_t i = 0; i < 10; i++) {
1062  testBasicRequest();
1063  }
1064  httpSession_->destroy();
1065 }
TEST_F ( HTTPUpstreamSessionTest  ,
TestFirstHeaderByteEventTracker   
)

Definition at line 1067 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, handler(), proxygen::HTTPTransaction::incrementPendingByteEvents(), testing::Invoke(), and uint64_t.

1067  {
1068  auto byteEventTracker = setMockByteEventTracker();
1069 
1070  EXPECT_CALL(*byteEventTracker, addFirstHeaderByteEvent(_, _))
1071  .WillOnce(Invoke([] (uint64_t /*byteNo*/,
1072  HTTPTransaction* txn) {
1074  }));
1075 
1076  InSequence enforceOrder;
1077 
1078  auto handler = openTransaction();
1079  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1080  EXPECT_TRUE(msg->getIsChunked());
1081  EXPECT_FALSE(msg->getIsUpgraded());
1082  EXPECT_EQ(200, msg->getStatusCode());
1083  });
1084  handler->expectEOM();
1085  handler->expectDetachTransaction();
1086 
1087  handler->sendRequest();
1088  readAndLoop("HTTP/1.1 200 OK\r\n"
1089  "Transfer-Encoding: chunked\r\n\r\n"
1090  "0\r\n\r\n");
1091 
1092  CHECK(httpSession_->supportsMoreTransactions());
1093  CHECK_EQ(httpSession_->getNumOutgoingStreams(), 0);
1094  handler->txn_->decrementPendingByteEvents();
1095  httpSession_->destroy();
1096 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTPUpstreamSessionTest  ,
Http10Keepalive   
)

Definition at line 1132 of file HTTPUpstreamSessionTest.cpp.

1132  {
1133  testBasicRequestHttp10(true);
1134  testBasicRequestHttp10(false);
1135 }
TEST_F ( HTTPUpstreamSessionTest  ,
BasicTrailers   
)

Definition at line 1137 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, and handler().

1137  {
1138  InSequence enforceOrder;
1139 
1140  auto handler = openTransaction();
1141  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1142  EXPECT_TRUE(msg->getIsChunked());
1143  EXPECT_FALSE(msg->getIsUpgraded());
1144  EXPECT_EQ(200, msg->getStatusCode());
1145  });
1146  EXPECT_CALL(*handler, onTrailers(_));
1147  handler->expectEOM();
1148  handler->expectDetachTransaction();
1149 
1150  handler->sendRequest();
1151  readAndLoop("HTTP/1.1 200 OK\r\n"
1152  "Transfer-Encoding: chunked\r\n\r\n"
1153  "0\r\n"
1154  "X-Trailer1: foo\r\n"
1155  "\r\n");
1156 
1157  CHECK(httpSession_->supportsMoreTransactions());
1158  CHECK_EQ(httpSession_->getNumOutgoingStreams(), 0);
1159  httpSession_->destroy();
1160 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTP2UpstreamSessionTest  ,
BasicTrailers   
)

Definition at line 1162 of file HTTPUpstreamSessionTest.cpp.

References folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_EQ, proxygen::HTTPMessage::getHeaders(), handler(), folly::IOBuf::length(), makeBuf(), makeServerCodec(), folly::IOBufQueue::move(), folly::gen::move, gmock_output_test::output, proxygen::HTTPHeaders::set(), and proxygen::HTTPMessage::setStatusCode().

1162  {
1163  auto egressCodec = makeServerCodec();
1165 
1166  egressCodec->generateSettings(output);
1167 
1168  HTTPMessage resp;
1169  resp.setStatusCode(200);
1170  resp.getHeaders().set("header1", "value1");
1171  egressCodec->generateHeader(output, 1, resp);
1172  auto buf = makeBuf(100);
1173  egressCodec->generateBody(
1174  output, 1, std::move(buf), HTTPCodec::NoPadding, false /* eom */);
1175  HTTPHeaders trailers;
1176  trailers.set("trailer2", "value2");
1177  egressCodec->generateTrailers(output, 1, trailers);
1178 
1179  std::unique_ptr<folly::IOBuf> input = output.move();
1180  input->coalesce();
1181 
1182  auto handler = openTransaction();
1183 
1184  handler->expectHeaders([&](std::shared_ptr<HTTPMessage> msg) {
1185  EXPECT_EQ(200, msg->getStatusCode());
1186  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty("header1"), "value1");
1187  });
1188  handler->expectBody();
1189  handler->expectTrailers([&](std::shared_ptr<HTTPHeaders> trailers) {
1190  EXPECT_EQ(trailers->getSingleOrEmpty("trailer2"), "value2");
1191  });
1192  handler->expectEOM();
1193  handler->expectDetachTransaction();
1194 
1195  handler->sendRequest();
1196  readAndLoop(input->data(), input->length());
1197 
1198  httpSession_->destroy();
1199 }
ByteRange coalesce()
Definition: IOBuf.h:1095
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint8_t * data() const
Definition: IOBuf.h:499
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
static Options cacheChainLength()
Definition: IOBufQueue.h:83
std::size_t length() const
Definition: IOBuf.h:533
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
void setStatusCode(uint16_t status)
TEST_F ( HTTP2UpstreamSessionTest  ,
HeadersThenBodyThenHeaders   
)

Definition at line 1201 of file HTTPUpstreamSessionTest.cpp.

References ASSERT_EQ, folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_EQ, EXPECT_TRUE, proxygen::HTTPMessage::getHeaders(), proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorIngressStateTransition, folly::IOBuf::length(), makeBuf(), makeServerCodec(), folly::IOBufQueue::move(), folly::gen::move, gmock_output_test::output, proxygen::HTTPHeaders::set(), proxygen::HTTPMessage::setStatusCode(), string, and proxygen::Exception::what().

1201  {
1202  auto egressCodec = makeServerCodec();
1204 
1205  egressCodec->generateSettings(output);
1206 
1207  HTTPMessage resp;
1208  resp.setStatusCode(200);
1209  resp.getHeaders().set("header1", "value1");
1210  egressCodec->generateHeader(output, 1, resp);
1211  auto buf = makeBuf(100);
1212  egressCodec->generateBody(
1213  output, 1, std::move(buf), HTTPCodec::NoPadding, false /* eom */);
1214  // generate same headers again on the same stream
1215  egressCodec->generateHeader(output, 1, resp);
1216 
1217  std::unique_ptr<folly::IOBuf> input = output.move();
1218  input->coalesce();
1219 
1220  auto handler = openTransaction();
1221 
1222  handler->expectHeaders([&](std::shared_ptr<HTTPMessage> msg) {
1223  EXPECT_EQ(200, msg->getStatusCode());
1224  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty("header1"), "value1");
1225  });
1226  handler->expectBody();
1227  handler->expectError([&](const HTTPException& err) {
1230  ASSERT_EQ(
1231  "Invalid ingress state transition, state=RegularBodyReceived, "
1232  "event=onHeaders, streamID=1",
1233  std::string(err.what()));
1234  });
1235  handler->expectDetachTransaction();
1236 
1237  handler->sendRequest();
1238  readAndLoop(input->data(), input->length());
1239 
1240  httpSession_->destroy();
1241 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
ByteRange coalesce()
Definition: IOBuf.h:1095
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint8_t * data() const
Definition: IOBuf.h:499
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
static Options cacheChainLength()
Definition: IOBufQueue.h:83
std::size_t length() const
Definition: IOBuf.h:533
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
const char * string
Definition: Conv.cpp:212
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
void setStatusCode(uint16_t status)
TEST_F ( HTTPUpstreamSessionTest  ,
TwoRequestsWithPause   
)

Definition at line 1243 of file HTTPUpstreamSessionTest.cpp.

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

1243  {
1244  InSequence enforceOrder;
1245 
1246  auto handler = openTransaction();
1247  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1248  EXPECT_TRUE(msg->getIsChunked());
1249  EXPECT_FALSE(msg->getIsUpgraded());
1250  EXPECT_EQ(200, msg->getStatusCode());
1251  });
1252 
1253  handler->expectEOM([&] () { handler->txn_->pauseIngress(); });
1254  handler->expectDetachTransaction();
1255 
1256  handler->sendRequest();
1257  readAndLoop("HTTP/1.1 200 OK\r\n"
1258  "Transfer-Encoding: chunked\r\n\r\n"
1259  "0\r\n\r\n");
1260 
1261  // Even though the previous transaction paused ingress just before it
1262  // finished up, reads resume automatically when the number of
1263  // transactions goes to zero. This way, the second request can read
1264  // without having to call resumeIngress()
1265  testBasicRequest();
1266  httpSession_->destroy();
1267 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTPUpstreamTimeoutTest  ,
WriteTimeoutAfterResponse   
)

Definition at line 1270 of file HTTPUpstreamSessionTest.cpp.

References ASSERT_EQ, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::HTTPException::getDirection(), proxygen::getPostRequest(), proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorWriteTimeout, string, and proxygen::Exception::what().

1270  {
1271  // Test where the upstream session times out while writing the request
1272  // to the server, but after the server has already sent back a full
1273  // response.
1274  pauseWrites_ = true;
1275  HTTPMessage req = getPostRequest();
1276 
1277  InSequence enforceOrder;
1278  auto handler = openTransaction();
1279  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1280  EXPECT_TRUE(msg->getIsChunked());
1281  EXPECT_FALSE(msg->getIsUpgraded());
1282  EXPECT_EQ(200, msg->getStatusCode());
1283  });
1284  handler->expectEOM();
1285  handler->expectError([&] (const HTTPException& err) {
1287  ASSERT_EQ(err.getDirection(),
1288  HTTPException::Direction::INGRESS_AND_EGRESS);
1290  ASSERT_EQ(
1291  folly::to<std::string>("WriteTimeout on transaction id: ",
1292  handler->txn_->getID()),
1293  std::string(err.what()));
1294  });
1295  handler->expectDetachTransaction();
1296 
1297  handler->txn_->sendHeaders(req);
1298  // Don't send the body, but get a response immediately
1299  readAndLoop("HTTP/1.1 200 OK\r\n"
1300  "Transfer-Encoding: chunked\r\n\r\n"
1301  "0\r\n\r\n");
1302 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
Direction getDirection() const
Definition: HTTPException.h:67
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( HTTPUpstreamSessionTest  ,
SetTransactionTimeout   
)

Definition at line 1304 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, EXPECT_TRUE, and handler().

1304  {
1305  // Test that setting a new timeout on the transaction will cancel
1306  // the old one.
1307  auto handler = openTransaction();
1308  handler->expectDetachTransaction();
1309 
1310  EXPECT_TRUE(handler->txn_->hasIdleTimeout());
1311  handler->txn_->setIdleTimeout(std::chrono::milliseconds(747));
1312  EXPECT_TRUE(handler->txn_->hasIdleTimeout());
1313  EXPECT_TRUE(handler->txn_->isScheduled());
1314  EXPECT_EQ(transactionTimeouts_->count(), 1);
1315  handler->txn_->sendAbort();
1316  eventBase_.loop();
1317 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST_F ( HTTPUpstreamSessionTest  ,
ReadTimeout   
)

Definition at line 1319 of file HTTPUpstreamSessionTest.cpp.

References wangle::ConnectionManager::makeUnique().

1319  {
1321  httpSession_->setController(&controller);
1323  &eventBase_, std::chrono::milliseconds(50));
1324  cm->addConnection(httpSession_, true);
1325  eventBase_.loop();
1326 }
static UniquePtr makeUnique(Args &&...args)
TEST_F ( HTTPUpstreamSessionTest  ,
100ContinueKeepalive   
)

Definition at line 1328 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::getGetRequest(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_EXPECT, and proxygen::HTTPHeaders::set().

1328  {
1329  // Test a request with 100 continue on a keepalive connection. Then make
1330  // another request.
1331  HTTPMessage req = getGetRequest();
1332  req.getHeaders().set(HTTP_HEADER_EXPECT, "100-continue");
1333 
1334  InSequence enforceOrder;
1335 
1336  auto handler = openTransaction();
1337  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1338  EXPECT_FALSE(msg->getIsChunked());
1339  EXPECT_FALSE(msg->getIsUpgraded());
1340  EXPECT_EQ(100, msg->getStatusCode());
1341  });
1342  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1343  EXPECT_TRUE(msg->getIsChunked());
1344  EXPECT_FALSE(msg->getIsUpgraded());
1345  EXPECT_EQ(200, msg->getStatusCode());
1346  });
1347  handler->expectEOM();
1348  handler->expectDetachTransaction();
1349 
1350  handler->sendRequest(req);
1351  readAndLoop("HTTP/1.1 100 Continue\r\n\r\n"
1352  "HTTP/1.1 200 OK\r\n"
1353  "Transfer-Encoding: chunked\r\n\r\n"
1354  "0\r\n\r\n");
1355 
1356  // Now make sure everything still works
1357  testBasicRequest();
1358  httpSession_->destroy();
1359 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTPUpstreamSessionTest  ,
417Keepalive   
)

Definition at line 1361 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, proxygen::getGetRequest(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_EXPECT, and proxygen::HTTPHeaders::set().

1361  {
1362  // Test a request with 100 continue on a keepalive connection. Then make
1363  // another request after the expectation fails.
1364  HTTPMessage req = getGetRequest();
1365  req.getHeaders().set(HTTP_HEADER_EXPECT, "100-continue");
1366 
1367  InSequence enforceOrder;
1368 
1369  auto handler = openTransaction();
1370  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1371  EXPECT_FALSE(msg->getIsChunked());
1372  EXPECT_FALSE(msg->getIsUpgraded());
1373  EXPECT_EQ(417, msg->getStatusCode());
1374  });
1375  handler->expectEOM();
1376  handler->expectDetachTransaction();
1377 
1378  handler->sendRequest(req);
1379  readAndLoop("HTTP/1.1 417 Expectation Failed\r\n"
1380  "Content-Length: 0\r\n\r\n");
1381 
1382  // Now make sure everything still works
1383  testBasicRequest();
1384  EXPECT_FALSE(sessionDestroyed_);
1385  httpSession_->destroy();
1386 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTPUpstreamSessionTest  ,
101Upgrade   
)

Definition at line 1388 of file HTTPUpstreamSessionTest.cpp.

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

1388  {
1389  // Test an upgrade request with sending 101 response. Then send
1390  // some data and check the onBody callback contents
1391  HTTPMessage req = getGetRequest();
1392  req.getHeaders().set(HTTP_HEADER_UPGRADE, "http/2.0");
1393 
1394  InSequence enforceOrder;
1395 
1396  auto handler = openTransaction();
1397  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1398  EXPECT_FALSE(msg->getIsChunked());
1399  EXPECT_EQ(101, msg->getStatusCode());
1400  });
1401  EXPECT_CALL(*handler, onUpgrade(_));
1402  EXPECT_CALL(*handler, onBody(_))
1403  .WillOnce(ExpectString("Test Body\r\n"));
1404  handler->expectEOM();
1405  handler->expectDetachTransaction();
1406 
1407  handler->sendRequest(req);
1408  eventBase_.loop();
1409  readAndLoop("HTTP/1.1 101 Switching Protocols\r\n"
1410  "Upgrade: http/2.0\r\n\r\n"
1411  "Test Body\r\n");
1412  readCallback_->readEOF();
1413  eventBase_.loop();
1414 
1415  CHECK_EQ(httpSession_->getNumOutgoingStreams(), 0);
1416  httpSession_->destroy();
1417 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradeNativeH2   
)

Definition at line 1473 of file HTTPUpstreamSessionTest.cpp.

1473  {
1474  testSimpleUpgrade("h2c", "h2c", CodecProtocol::HTTP_2);
1475 }
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradeNativeUnknown   
)

Definition at line 1478 of file HTTPUpstreamSessionTest.cpp.

1478  {
1479  testSimpleUpgrade("blarf, h2c", "h2c", CodecProtocol::HTTP_2);
1480 }
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradeNativeWhitespace   
)

Definition at line 1483 of file HTTPUpstreamSessionTest.cpp.

1483  {
1484  testSimpleUpgrade("blarf, \th2c\t, xyz", "h2c",
1485  CodecProtocol::HTTP_2);
1486 }
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradeNativeJunk   
)

Definition at line 1489 of file HTTPUpstreamSessionTest.cpp.

1489  {
1490  testSimpleUpgrade(",,,, ,,\t~^%$(*&@(@$^^*(,h2c", "h2c",
1491  CodecProtocol::HTTP_2);
1492 }
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgrade101Unexpected   
)

Definition at line 1494 of file HTTPUpstreamSessionTest.cpp.

References testing::_, dummy(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, and handler().

1494  {
1495  InSequence dummy;
1496  auto handler = openTransaction();
1497 
1498  EXPECT_CALL(*handler, onError(_));
1499  handler->expectDetachTransaction();
1500 
1501  handler->sendRequest();
1502  eventBase_.loop();
1503  readAndLoop(folly::to<string>("HTTP/1.1 101 Switching Protocols\r\n"
1504  "Upgrade: spdy/3\r\n"
1505  "\r\n"));
1506  EXPECT_EQ(readCallback_, nullptr);
1507  EXPECT_TRUE(sessionDestroyed_);
1508 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void dummy()
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgrade101MissingUpgrade   
)

Definition at line 1510 of file HTTPUpstreamSessionTest.cpp.

References testing::_, dummy(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, proxygen::getUpgradeRequest(), and handler().

1510  {
1511  InSequence dummy;
1512  auto handler = openTransaction();
1513 
1514  EXPECT_CALL(*handler, onError(_));
1515  handler->expectDetachTransaction();
1516 
1517  handler->sendRequest(getUpgradeRequest("spdy/3"));
1518  readAndLoop(folly::to<string>("HTTP/1.1 101 Switching Protocols\r\n"
1519  "\r\n"));
1520  EXPECT_EQ(readCallback_, nullptr);
1521  EXPECT_TRUE(sessionDestroyed_);
1522 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void dummy()
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
HTTPMessage getUpgradeRequest(const std::string &upgradeHeader, HTTPMethod method, uint32_t bodyLen)
Definition: TestUtils.cpp:161
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgrade101BogusHeader   
)

Definition at line 1524 of file HTTPUpstreamSessionTest.cpp.

References testing::_, dummy(), EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, proxygen::getUpgradeRequest(), and handler().

1524  {
1525  InSequence dummy;
1526  auto handler = openTransaction();
1527 
1528  EXPECT_CALL(*handler, onError(_));
1529  handler->expectDetachTransaction();
1530 
1531  handler->sendRequest(getUpgradeRequest("spdy/3"));
1532  eventBase_.loop();
1533  readAndLoop(folly::to<string>("HTTP/1.1 101 Switching Protocols\r\n"
1534  "Upgrade: blarf\r\n"
1535  "\r\n"));
1536  EXPECT_EQ(readCallback_, nullptr);
1537  EXPECT_TRUE(sessionDestroyed_);
1538 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
void dummy()
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
HTTPMessage getUpgradeRequest(const std::string &upgradeHeader, HTTPMethod method, uint32_t bodyLen)
Definition: TestUtils.cpp:161
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradePost100   
)

Definition at line 1540 of file HTTPUpstreamSessionTest.cpp.

References dummy(), EXPECT_EQ, handler(), makeBuf(), and folly::gen::move.

1540  {
1541  InSequence dummy;
1542  auto handler = openTransaction();
1543 
1544  handler->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1545  EXPECT_EQ(100, msg->getStatusCode());
1546  });
1547  handler->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1548  EXPECT_EQ(200, msg->getStatusCode());
1549  });
1550  handler->expectBody();
1551  handler->expectEOM();
1552  handler->expectDetachTransaction();
1553 
1554  auto txn = handler->txn_;
1555  HTTPMessage req = getUpgradePostRequest(100, "h2c", true /* 100 */);
1556  txn->sendHeaders(req);
1557  auto buf = makeBuf(100);
1558  txn->sendBody(std::move(buf));
1559  txn->sendEOM();
1560  eventBase_.loop();
1561  readAndLoop(folly::to<string>("HTTP/1.1 100 Continue\r\n"
1562  "\r\n"
1563  "HTTP/1.1 101 Switching Protocols\r\n"
1564  "Upgrade: h2c\r\n"
1565  "\r\n"));
1566  readAndLoop(
1567  getResponseBuf(CodecProtocol::HTTP_2, txn->getID(), 200, 100).get());
1568  httpSession_->destroy();
1569 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void dummy()
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradePost100Http2   
)

Definition at line 1571 of file HTTPUpstreamSessionTest.cpp.

References dummy(), EXPECT_EQ, handler(), makeBuf(), and folly::gen::move.

1571  {
1572  InSequence dummy;
1573  auto handler = openTransaction();
1574 
1575  handler->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1576  EXPECT_EQ(100, msg->getStatusCode());
1577  });
1578  handler->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1579  EXPECT_EQ(200, msg->getStatusCode());
1580  });
1581  handler->expectBody();
1582  handler->expectEOM();
1583  handler->expectDetachTransaction();
1584 
1585  auto txn = handler->txn_;
1586  HTTPMessage req = getUpgradePostRequest(100, "h2c");
1587  txn->sendHeaders(req);
1588  auto buf = makeBuf(100);
1589  txn->sendBody(std::move(buf));
1590  txn->sendEOM();
1591  eventBase_.loop();
1592  readAndLoop(folly::to<string>("HTTP/1.1 101 Switching Protocols\r\n"
1593  "Upgrade: h2c\r\n"
1594  "\r\n"));
1595  readAndLoop(getResponseBuf(CodecProtocol::HTTP_2,
1596  txn->getID(), 200, 100, true).get());
1597  httpSession_->destroy();
1598 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void dummy()
TEST_F ( HTTPUpstreamSessionTest  ,
HttpUpgradeOnTxn2   
)

Definition at line 1600 of file HTTPUpstreamSessionTest.cpp.

References dummy(), EXPECT_EQ, and proxygen::getUpgradeRequest().

1600  {
1601  InSequence dummy;
1602  auto handler1 = openTransaction();
1603 
1604  handler1->expectHeaders([] (std::shared_ptr<HTTPMessage> msg) {
1605  EXPECT_EQ(200, msg->getStatusCode());
1606  });
1607  handler1->expectBody();
1608  handler1->expectEOM();
1609  handler1->expectDetachTransaction();
1610 
1611  auto txn = handler1->txn_;
1612  HTTPMessage req = getUpgradeRequest("spdy/3");
1613  txn->sendHeaders(req);
1614  txn->sendEOM();
1615  readAndLoop("HTTP/1.1 200 Ok\r\n"
1616  "Content-Length: 10\r\n"
1617  "\r\n"
1618  "abcdefghij");
1619  eventBase_.loop();
1620 
1621  auto handler2 = openTransaction();
1622 
1623  txn = handler2->txn_;
1624  txn->sendHeaders(req);
1625  txn->sendEOM();
1626 
1627  handler2->expectHeaders();
1628  handler2->expectEOM();
1629  handler2->expectDetachTransaction();
1630  readAndLoop("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
1631  httpSession_->destroy();
1632 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void dummy()
HTTPMessage getUpgradeRequest(const std::string &upgradeHeader, HTTPMethod method, uint32_t bodyLen)
Definition: TestUtils.cpp:161
TEST_F ( HTTPUpstreamRecvStreamTest  ,
UpgradeFlowControl   
)

Definition at line 1641 of file HTTPUpstreamSessionTest.cpp.

References testing::_, dummy(), EXPECT_CALL, proxygen::HTTP2Codec::getDefaultWindowSize(), testing::Invoke(), proxygen::HTTPParallelCodec::setCallback(), and settings.

1641  {
1642  InSequence dummy;
1643  testSimpleUpgrade("h2c", "h2c", CodecProtocol::HTTP_2);
1644 
1645  HTTP2Codec serverCodec(TransportDirection::DOWNSTREAM);
1647  serverCodec.setCallback(&callbacks);
1648  EXPECT_CALL(callbacks, onSettings(_))
1649  .WillOnce(Invoke([this] (const SettingsList& settings) {
1650  if (flowControl_[0] > 0) {
1651  for (const auto& setting: settings) {
1652  if (setting.id == SettingsId::INITIAL_WINDOW_SIZE) {
1653  EXPECT_EQ(flowControl_[0], setting.value);
1654  }
1655  }
1656  }
1657  }));
1658  EXPECT_CALL(callbacks, onWindowUpdate(0, flowControl_[2] -
1659  serverCodec.getDefaultWindowSize()));
1660  size_t initWindow = flowControl_[0] > 0 ?
1661  flowControl_[0] : serverCodec.getDefaultWindowSize();
1662  EXPECT_CALL(callbacks, onWindowUpdate(1, flowControl_[1] - initWindow));
1663  parseOutput(serverCodec);
1664 }
static http_parser_settings settings
Definition: test.c:1529
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void dummy()
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( NoFlushUpstreamSessionTest  ,
SessionPausedStartPaused   
)

Definition at line 1690 of file HTTPUpstreamSessionTest.cpp.

References proxygen::getGetRequest(), and makeBuf().

1690  {
1691  // If the session is paused, new upstream transactions should start
1692  // paused too.
1693  HTTPMessage req = getGetRequest();
1694 
1695  InSequence enforceOrder;
1696 
1697  auto handler1 = openNiceTransaction();
1698  handler1->txn_->sendHeaders(req);
1699  Mock::VerifyAndClearExpectations(handler1.get());
1700  // The session pauses all txns since no writeSuccess for too many bytes
1701  handler1->expectEgressPaused();
1702  // Send a body big enough to pause egress
1703  handler1->txn_->sendBody(makeBuf(httpSession_->getWriteBufferLimit()));
1704  eventBase_.loop();
1705  Mock::VerifyAndClearExpectations(handler1.get());
1706 
1707  auto handler2 = openNiceTransaction(true /* expect start paused */);
1708  eventBase_.loop();
1709  Mock::VerifyAndClearExpectations(handler2.get());
1710 
1711  httpSession_->dropConnection();
1712 }
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
TEST_F ( NoFlushUpstreamSessionTest  ,
DeleteTxnOnUnpause   
)

Definition at line 1714 of file HTTPUpstreamSessionTest.cpp.

References proxygen::getGetRequest(), and makeBuf().

1714  {
1715  // Test where the handler gets onEgressPaused() and triggers another
1716  // HTTPSession call to iterate over all transactions (to ensure nested
1717  // iteration works).
1718 
1719  HTTPMessage req = getGetRequest();
1720 
1721  InSequence enforceOrder;
1722 
1723  auto handler1 = openNiceTransaction();
1724  auto handler2 = openNiceTransaction();
1725  auto handler3 = openNiceTransaction();
1726  handler2->expectEgressPaused([this] {
1727  // This time it is invoked by the session on all transactions
1728  httpSession_->dropConnection();
1729  });
1730  handler2->txn_->sendHeaders(req);
1731  // This happens when the body write fills the txn egress queue
1732  // Send a body big enough to pause egress
1733  handler2->txn_->onIngressWindowUpdate(100);
1734  handler2->txn_->sendBody(makeBuf(httpSession_->getWriteBufferLimit() + 1));
1735  eventBase_.loop();
1736 }
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
TEST_F ( HTTP2UpstreamSessionTest  ,
ServerPush   
)

Definition at line 1798 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::cacheChainLength(), folly::IOBuf::coalesce(), folly::IOBuf::data(), EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::MockHTTPHandler::expectBody(), proxygen::MockHTTPHandler::expectDetachTransaction(), proxygen::MockHTTPHandler::expectEOM(), proxygen::MockHTTPHandler::expectHeaders(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_HOST, testing::Invoke(), folly::IOBuf::length(), makeBuf(), makeServerCodec(), folly::IOBufQueue::move(), folly::gen::move, gmock_output_test::output, proxygen::HTTPHeaders::set(), proxygen::HTTPTransaction::setHandler(), proxygen::HTTPMessage::setStatusCode(), and proxygen::HTTPMessage::setURL().

1798  {
1799  httpSession_->setEgressSettings({{SettingsId::ENABLE_PUSH, 1}});
1800 
1801  auto egressCodec = makeServerCodec();
1803 
1804  HTTPMessage push;
1805  push.getHeaders().set("HOST", "www.foo.com");
1806  push.setURL("https://www.foo.com/");
1807  egressCodec->generateSettings(output);
1808  // PUSH_PROMISE
1809  egressCodec->generatePushPromise(output, 2, push, 1);
1810 
1811  // Pushed resource
1812  HTTPMessage resp;
1813  resp.setStatusCode(200);
1814  resp.getHeaders().set("ohai", "push");
1815  egressCodec->generateHeader(output, 2, resp);
1816  auto buf = makeBuf(100);
1817  egressCodec->generateBody(output, 2, std::move(buf), HTTPCodec::NoPadding,
1818  true /* eom */);
1819 
1820  // Original resource
1821  resp.getHeaders().set("ohai", "orig");
1822  egressCodec->generateHeader(output, 1, resp);
1823  buf = makeBuf(100);
1824  egressCodec->generateBody(output, 1, std::move(buf), HTTPCodec::NoPadding,
1825  true /* eom */);
1826 
1827  std::unique_ptr<folly::IOBuf> input = output.move();
1828  input->coalesce();
1829 
1830  MockHTTPHandler pushHandler;
1831 
1832  InSequence enforceOrder;
1833 
1834  auto handler = openTransaction();
1835  EXPECT_CALL(*handler, onPushedTransaction(_))
1836  .WillOnce(Invoke([&pushHandler] (HTTPTransaction* pushTxn) {
1837  pushTxn->setHandler(&pushHandler);
1838  }));
1839  EXPECT_CALL(pushHandler, setTransaction(_));
1840  pushHandler.expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1841  EXPECT_EQ(httpSession_->getNumIncomingStreams(), 1);
1842  EXPECT_TRUE(msg->getIsChunked());
1843  EXPECT_FALSE(msg->getIsUpgraded());
1844  EXPECT_EQ(msg->getPath(), "/");
1845  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty(HTTP_HEADER_HOST),
1846  "www.foo.com");
1847  });
1848  pushHandler.expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1849  EXPECT_EQ(msg->getStatusCode(), 200);
1850  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty("ohai"), "push");
1851  });
1852  pushHandler.expectBody();
1853  pushHandler.expectEOM();
1854  pushHandler.expectDetachTransaction();
1855 
1856  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1857  EXPECT_FALSE(msg->getIsUpgraded());
1858  EXPECT_EQ(200, msg->getStatusCode());
1859  EXPECT_EQ(msg->getHeaders().getSingleOrEmpty("ohai"), "orig");
1860  });
1861  handler->expectBody();
1862  handler->expectEOM();
1863  handler->expectDetachTransaction();
1864 
1865  handler->sendRequest();
1866  readAndLoop(input->data(), input->length());
1867 
1868  EXPECT_EQ(httpSession_->getNumIncomingStreams(), 0);
1869  httpSession_->destroy();
1870 }
virtual void setHandler(Handler *handler)
ByteRange coalesce()
Definition: IOBuf.h:1095
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint8_t * data() const
Definition: IOBuf.h:499
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
ParseURL setURL(T &&url)
Definition: HTTPMessage.h:183
static Options cacheChainLength()
Definition: IOBufQueue.h:83
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
std::size_t length() const
Definition: IOBuf.h:533
void expectEOM(std::function< void()> callback=std::function< void()>())
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
void expectDetachTransaction(std::function< void()> callback=std::function< void()>())
void expectHeaders(std::function< void()> callback=std::function< void()>())
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void expectBody(std::function< void()> callback=std::function< void()>())
void setStatusCode(uint16_t status)
TEST_F ( MockHTTP2UpstreamTest  ,
ParseErrorNoTxn   
)

Definition at line 1887 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::append(), EXPECT_CALL, proxygen::getPostRequest(), handler(), testing::Invoke(), proxygen::kErrorParseHeader, testing::Return(), proxygen::HTTPException::setCodecStatusCode(), proxygen::Exception::setProxygenError(), and fizz::detail::writeBuf().

1887  {
1888  // 1) Create streamID == 1
1889  // 2) Send request
1890  // 3) Detach handler
1891  // 4) Get an ingress parse error on reply
1892  // Expect that the codec should be asked to generate an abort on streamID==1
1893 
1894  // Setup the codec expectations.
1895  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _))
1897  const HTTPMessage&, bool, HTTPHeaderSize*) {
1898  writeBuf.append("1", 1);
1899  }));
1900  EXPECT_CALL(*codecPtr_, generateEOM(_, _))
1901  .WillOnce(Return(20));
1902  EXPECT_CALL(*codecPtr_, generateRstStream(_, 1, _));
1903 
1904  // 1)
1905  auto handler = openTransaction();
1906 
1907  // 2)
1908  handler->sendRequest(getPostRequest());
1909 
1910  // 3) Note this sendAbort() doesn't destroy the txn since byte events are
1911  // enqueued
1912  handler->txn_->sendAbort();
1913 
1914  // 4)
1915  HTTPException ex(HTTPException::Direction::INGRESS_AND_EGRESS, "foo");
1916  ex.setProxygenError(kErrorParseHeader);
1917  ex.setCodecStatusCode(ErrorCode::REFUSED_STREAM);
1918  codecCb_->onError(1, ex, true);
1919 
1920  // cleanup
1921  handler->expectDetachTransaction();
1922  httpSession_->dropConnection();
1923  eventBase_.loop();
1924 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
void handler(int, siginfo_t *, void *)
void writeBuf(const Buf &buf, folly::io::Appender &out)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
TEST_F ( MockHTTPUpstreamTest  ,
0MaxOutgoingTxns   
)

Definition at line 1926 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_TRUE.

1926  {
1927  // Test where an upstream session gets a SETTINGS frame with 0 max
1928  // outgoing transactions. In our implementation, we jsut send a GOAWAY
1929  // and close the connection.
1930 
1931  codecCb_->onSettings({{SettingsId::MAX_CONCURRENT_STREAMS, 0}});
1932  EXPECT_TRUE(transactionsFull_);
1933  httpSession_->dropConnection();
1934 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST_F ( MockHTTPUpstreamTest  ,
OutgoingTxnSettings   
)

Definition at line 1936 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_FALSE, and EXPECT_TRUE.

1936  {
1937  // Create 2 transactions, then receive a settings frame from
1938  // the server indicating 1 parallel transaction at a time is allowed.
1939  // Then get another SETTINGS frame indicating 100 max parallel
1940  // transactions. Expect that HTTPSession invokes both info callbacks.
1941 
1942  NiceMock<MockHTTPHandler> handler1;
1943  NiceMock<MockHTTPHandler> handler2;
1944  httpSession_->newTransaction(&handler1);
1945  httpSession_->newTransaction(&handler2);
1946 
1947  codecCb_->onSettings({{SettingsId::MAX_CONCURRENT_STREAMS, 1}});
1948  EXPECT_TRUE(transactionsFull_);
1949  codecCb_->onSettings({{SettingsId::MAX_CONCURRENT_STREAMS, 100}});
1950  EXPECT_FALSE(transactionsFull_);
1951  httpSession_->dropConnection();
1952 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( MockHTTPUpstreamTest  ,
IngressGoawayDrain   
)

Definition at line 1954 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, handler(), proxygen::makeResponse(), and folly::gen::move.

1954  {
1955  // Tests whether the session drains existing transactions and
1956  // deletes itself after receiving a GOAWAY.
1957 
1958  InSequence enforceOrder;
1959 
1960  auto handler = openTransaction();
1961  EXPECT_CALL(*handler, onGoaway(ErrorCode::NO_ERROR));
1962  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
1963  EXPECT_FALSE(msg->getIsUpgraded());
1964  EXPECT_EQ(200, msg->getStatusCode());
1965  });
1966  handler->expectEOM();
1967  handler->expectDetachTransaction();
1968 
1969  // Send the GET request
1970  handler->sendRequest();
1971 
1972  // Receive GOAWAY frame with last good stream as 1
1973  codecCb_->onGoaway(1, ErrorCode::NO_ERROR);
1974 
1975  // New transactions cannot be created afrer goaway
1976  EXPECT_FALSE(httpSession_->isReusable());
1977  EXPECT_EQ(httpSession_->newTransaction(handler.get()), nullptr);
1978 
1979  // Receive 200 OK
1980  auto resp = makeResponse(200);
1981  codecCb_->onMessageBegin(1, resp.get());
1982  codecCb_->onHeadersComplete(1, std::move(resp));
1983  codecCb_->onMessageComplete(1, false);
1984  eventBase_.loop();
1985 
1986  // Session will delete itself after getting the response
1987 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
#define EXPECT_CALL(obj, call)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( MockHTTPUpstreamTest  ,
Goaway   
)

Definition at line 1989 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, proxygen::MockHTTPHandler::expectDetachTransaction(), proxygen::MockHTTPHandler::expectEOM(), proxygen::MockHTTPHandler::expectHeaders(), proxygen::MockHTTPHandler::expectTransaction(), handler(), i, proxygen::makeResponse(), folly::gen::move, and proxygen::HTTPHandlerBase::sendRequest().

1989  {
1990  // Make sure existing txns complete successfully even if we drain the
1991  // upstream session
1992  const unsigned numTxns = 10;
1993  MockHTTPHandler handler[numTxns];
1994 
1995  InSequence enforceOrder;
1996 
1997  for (unsigned i = 0; i < numTxns; ++i) {
1998  handler[i].expectTransaction();
1999  handler[i].expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2000  EXPECT_FALSE(msg->getIsUpgraded());
2001  EXPECT_EQ(200, msg->getStatusCode());
2002  });
2003  httpSession_->newTransaction(&handler[i]);
2004 
2005  // Send the GET request
2006  handler[i].sendRequest();
2007 
2008  // Receive 200 OK
2009  auto resp = makeResponse(200);
2010  codecCb_->onMessageBegin(handler[i].txn_->getID(), resp.get());
2011  codecCb_->onHeadersComplete(handler[i].txn_->getID(), std::move(resp));
2012  }
2013 
2014  codecCb_->onGoaway(numTxns * 2 + 1, ErrorCode::NO_ERROR);
2015  for (unsigned i = 0; i < numTxns; ++i) {
2016  handler[i].expectEOM();
2017  handler[i].expectDetachTransaction();
2018  codecCb_->onMessageComplete(i*2 + 1, false);
2019  }
2020  eventBase_.loop();
2021 
2022  // Session will delete itself after drain completes
2023 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
void expectEOM(std::function< void()> callback=std::function< void()>())
void expectDetachTransaction(std::function< void()> callback=std::function< void()>())
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
void expectTransaction(std::function< void(HTTPTransaction *txn)> callback)
void expectHeaders(std::function< void()> callback=std::function< void()>())
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( MockHTTPUpstreamTest  ,
GoawayPreHeaders   
)

Definition at line 2025 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::append(), ASSERT_TRUE, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, proxygen::MockHTTPHandler::expectDetachTransaction(), proxygen::MockHTTPHandler::expectEOM(), proxygen::MockHTTPHandler::expectHeaders(), proxygen::MockHTTPHandler::expectTransaction(), proxygen::HTTPTransaction::getID(), handler(), testing::Invoke(), proxygen::makeResponse(), folly::gen::move, proxygen::HTTPHandlerBase::sendRequest(), string, proxygen::HTTPHandlerBase::txn_, and fizz::detail::writeBuf().

2025  {
2026  // Make sure existing txns complete successfully even if we drain the
2027  // upstream session
2029 
2030  InSequence enforceOrder;
2031 
2032  handler.expectTransaction();
2033  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _))
2034  .WillOnce(Invoke(
2035  [&](IOBufQueue& writeBuf,
2036  HTTPCodec::StreamID /*stream*/,
2037  const HTTPMessage& /*msg*/,
2038  bool /*eom*/,
2039  HTTPHeaderSize* /*size*/) { writeBuf.append("HEADERS", 7); }));
2040  handler.expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2041  EXPECT_FALSE(msg->getIsUpgraded());
2042  EXPECT_EQ(200, msg->getStatusCode());
2043  });
2044  httpSession_->newTransaction(&handler);
2045  httpSession_->drain();
2046 
2047  // Send the GET request
2048  handler.sendRequest();
2049 
2050  // Receive 200 OK
2051  auto resp = makeResponse(200);
2052  codecCb_->onMessageBegin(handler.txn_->getID(), resp.get());
2053  codecCb_->onHeadersComplete(handler.txn_->getID(), std::move(resp));
2054 
2055  codecCb_->onGoaway(1, ErrorCode::NO_ERROR);
2056  handler.expectEOM();
2057  handler.expectDetachTransaction();
2058  codecCb_->onMessageComplete(1, false);
2059  eventBase_.loop();
2060 
2061  auto buf = writes_.move();
2062  ASSERT_TRUE(buf != nullptr);
2063  EXPECT_EQ(buf->moveToFbString().data(), string("HEADERSGOAWAY"));
2064  // Session will delete itself after drain completes
2065 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
void writeBuf(const Buf &buf, folly::io::Appender &out)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void expectEOM(std::function< void()> callback=std::function< void()>())
void expectDetachTransaction(std::function< void()> callback=std::function< void()>())
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
void expectTransaction(std::function< void(HTTPTransaction *txn)> callback)
void expectHeaders(std::function< void()> callback=std::function< void()>())
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
HTTPCodec::StreamID getID() const
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( MockHTTPUpstreamTest  ,
NoWindowUpdateOnDrain   
)

Definition at line 2067 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBufQueue::append(), dummy(), EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_LT, handler(), testing::Invoke(), makeBuf(), proxygen::makeResponse(), min, folly::gen::move, testing::Return(), streamID, string, uint32_t, and fizz::detail::writeBuf().

2067  {
2068  EXPECT_CALL(*codecPtr_, supportsStreamFlowControl())
2069  .WillRepeatedly(Return(true));
2070 
2071  auto handler = openTransaction();
2072 
2073  handler->sendRequest();
2074  httpSession_->drain();
2075  auto streamID = handler->txn_->getID();
2076 
2077  EXPECT_CALL(*handler, onGoaway(ErrorCode::NO_ERROR));
2078  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2079  EXPECT_FALSE(msg->getIsUpgraded());
2080  EXPECT_EQ(200, msg->getStatusCode());
2081  });
2082  EXPECT_CALL(*handler, onBody(_))
2083  .Times(3);
2084  handler->expectEOM();
2085 
2086  handler->expectDetachTransaction();
2087 
2088  uint32_t outstanding = 0;
2089  uint32_t sendWindow = 65536;
2090  uint32_t toSend = sendWindow * 1.55;
2091 
2092  // We'll get exactly one window update because we are draining
2093  EXPECT_CALL(*codecPtr_, generateWindowUpdate(_, _, _))
2094  .WillOnce(Invoke([&](folly::IOBufQueue& writeBuf,
2095  HTTPCodec::StreamID /*stream*/,
2096  uint32_t delta) {
2097  EXPECT_EQ(delta, sendWindow);
2098  outstanding -= delta;
2099  uint32_t len = std::min(toSend, sendWindow - outstanding);
2100  EXPECT_LT(len, sendWindow);
2101  toSend -= len;
2102  EXPECT_EQ(toSend, 0);
2103  eventBase_.tryRunAfterDelay(
2104  [this, streamID, len] {
2105  failWrites_ = true;
2106  auto respBody = makeBuf(len);
2107  codecCb_->onBody(streamID, std::move(respBody), 0);
2108  codecCb_->onMessageComplete(streamID, false);
2109  },
2110  50);
2111 
2112  const std::string dummy("window");
2113  writeBuf.append(dummy);
2114  return 6;
2115  }));
2116 
2117  codecCb_->onGoaway(streamID, ErrorCode::NO_ERROR);
2118  auto resp = makeResponse(200);
2119  codecCb_->onMessageBegin(streamID, resp.get());
2120  codecCb_->onHeadersComplete(streamID, std::move(resp));
2121 
2122  // While there is room and the window and body to send
2123  while (sendWindow - outstanding > 0 && toSend > 0) {
2124  // Send up to a 36k chunk
2125  uint32_t len = std::min(toSend, uint32_t(36000));
2126  // limited by the available window
2127  len = std::min(len, sendWindow - outstanding);
2128  auto respBody = makeBuf(len);
2129  toSend -= len;
2130  outstanding += len;
2131  codecCb_->onBody(streamID, std::move(respBody), 0);
2132  }
2133 
2134  eventBase_.loop();
2135 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void writeBuf(const Buf &buf, folly::io::Appender &out)
LogLevel min
Definition: LogLevel.cpp:30
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
void dummy()
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_LT(val1, val2)
Definition: gtest.h:1930
uint32_t streamID
Definition: SPDYCodec.cpp:131
internal::ReturnAction< R > Return(R value)
TEST_F ( MockHTTPUpstreamTest  ,
GetWithBody   
)

Definition at line 2137 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, proxygen::getGetRequest(), proxygen::HTTPMessage::getHeaders(), handler(), proxygen::HTTP_HEADER_CONTENT_LENGTH, makeBuf(), and proxygen::HTTPHeaders::set().

2137  {
2138  // Should be allowed to send a GET request with body.
2140  HTTPMessage req = getGetRequest();
2142 
2143  InSequence enforceOrder;
2144 
2145  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _));
2146  EXPECT_CALL(*codecPtr_, generateBody(_, _, _, _, true));
2147 
2148  auto txn = httpSession_->newTransaction(&handler);
2149  txn->sendHeaders(req);
2150  txn->sendBody(makeBuf(10));
2151  txn->sendEOM();
2152 
2153  eventBase_.loop();
2154  httpSession_->dropConnection();
2155 }
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
void set(folly::StringPiece name, const std::string &value)
Definition: HTTPHeaders.h:119
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( MockHTTPUpstreamTest  ,
HeaderWithEom   
)

Definition at line 2157 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_TRUE, proxygen::getGetRequest(), and handler().

2157  {
2159  HTTPMessage req = getGetRequest();
2160  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, true, _));
2161 
2162  auto txn = httpSession_->newTransaction(&handler);
2163  txn->sendHeadersWithEOM(req);
2164  eventBase_.loop();
2165  EXPECT_TRUE(txn->isEgressComplete());
2166  httpSession_->dropConnection();
2167 }
void handler(int, siginfo_t *, void *)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( TestAbortPost1  ,
Test   
)

Definition at line 2265 of file HTTPUpstreamSessionTest.cpp.

2265 { doAbortTest(); }
TEST_F ( TestAbortPost2  ,
Test   
)

Definition at line 2266 of file HTTPUpstreamSessionTest.cpp.

2266 { doAbortTest(); }
TEST_F ( TestAbortPost3  ,
Test   
)

Definition at line 2267 of file HTTPUpstreamSessionTest.cpp.

2267 { doAbortTest(); }
TEST_F ( TestAbortPost4  ,
Test   
)

Definition at line 2268 of file HTTPUpstreamSessionTest.cpp.

2268 { doAbortTest(); }
TEST_F ( TestAbortPost5  ,
Test   
)

Definition at line 2269 of file HTTPUpstreamSessionTest.cpp.

2269 { doAbortTest(); }
TEST_F ( MockHTTPUpstreamTest  ,
AbortUpgrade   
)

Definition at line 2271 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, proxygen::getPostRequest(), handler(), makeBuf(), proxygen::makeResponse(), folly::gen::move, and streamID.

2271  {
2272  // This is basically the same test as above, just for the upgrade path
2273  InSequence enforceOrder;
2275  HTTPMessage req = getPostRequest(10);
2276 
2277  std::unique_ptr<HTTPMessage> resp = makeResponse(200);
2278 
2279  handler.expectTransaction();
2280  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _));
2281 
2282  auto txn = httpSession_->newTransaction(&handler);
2283  const auto streamID = txn->getID();
2284  txn->sendHeaders(req);
2285  txn->sendBody(makeBuf(5)); // only send half the body
2286 
2287  handler.expectHeaders();
2288  codecCb_->onHeadersComplete(streamID, std::move(resp));
2289 
2290  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID, _));
2291  handler.expectDetachTransaction();
2292  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID,
2293  ErrorCode::_SPDY_INVALID_STREAM));
2294  txn->sendAbort();
2295  codecCb_->onMessageComplete(streamID, true); // upgrade
2296  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID,
2297  ErrorCode::_SPDY_INVALID_STREAM));
2298  codecCb_->onMessageComplete(streamID, false); // eom
2299 
2300  eventBase_.loop();
2301 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
uint32_t streamID
Definition: SPDYCodec.cpp:131
TEST_F ( MockHTTPUpstreamTest  ,
DrainBeforeSendHeaders   
)

Definition at line 2303 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, handler(), and proxygen::makeResponse().

2303  {
2304  // Test that drain on session before sendHeaders() is called on open txn
2305 
2306  InSequence enforceOrder;
2307  MockHTTPHandler pushHandler;
2308 
2309  auto handler = openTransaction();
2310  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _));
2311 
2312  handler->expectHeaders();
2313  handler->expectEOM();
2314  handler->expectDetachTransaction();
2315 
2316  httpSession_->drain();
2317  handler->sendRequest();
2318  codecCb_->onHeadersComplete(handler->txn_->getID(), makeResponse(200));
2319  codecCb_->onMessageComplete(handler->txn_->getID(), false); // eom
2320 
2321  eventBase_.loop();
2322 }
void handler(int, siginfo_t *, void *)
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( MockHTTP2UpstreamTest  ,
ReceiveDoubleGoaway   
)

Definition at line 2324 of file HTTPUpstreamSessionTest.cpp.

References testing::_, ASSERT_EQ, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, proxygen::getGetRequest(), proxygen::Exception::getProxygenError(), proxygen::Exception::hasProxygenError(), proxygen::kErrorStreamUnacknowledged, string, and proxygen::Exception::what().

2324  {
2325  // Test that we handle receiving two goaways correctly
2326 
2327  InSequence enforceOrder;
2328  auto req = getGetRequest();
2329 
2330  // Open 2 txns but doesn't send headers yet
2331  auto handler1 = openTransaction();
2332  auto handler2 = openTransaction();
2333 
2334  // Get first goaway acking many un-started txns
2335  handler1->expectGoaway();
2336  handler2->expectGoaway();
2337  codecCb_->onGoaway(101, ErrorCode::NO_ERROR);
2338 
2339  // This txn should be alive since it was ack'd by the above goaway
2340  handler1->txn_->sendHeaders(req);
2341 
2342  // Second goaway acks the only the current outstanding transaction
2343  handler1->expectGoaway();
2344  handler2->expectGoaway();
2345  handler2->expectError([&] (const HTTPException& err) {
2348  ASSERT_EQ(
2349  folly::to<std::string>("StreamUnacknowledged on transaction id: ",
2350  handler2->txn_->getID()),
2351  std::string(err.what()));
2352  });
2353  handler2->expectDetachTransaction();
2354  codecCb_->onGoaway(handler1->txn_->getID(), ErrorCode::NO_ERROR);
2355 
2356  // Clean up
2357  httpSession_->drain();
2358  EXPECT_CALL(*codecPtr_, generateRstStream(_, handler1->txn_->getID(), _));
2359  handler1->expectDetachTransaction();
2360  handler1->txn_->sendAbort();
2361  eventBase_.loop();
2362 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( MockHTTP2UpstreamTest  ,
ServerPushInvalidAssoc   
)

Definition at line 2364 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::getGetRequest(), handler(), proxygen::makeResponse(), folly::gen::move, and streamID.

2364  {
2365  // Test that protocol error is generated on server push
2366  // with invalid assoc stream id
2367  InSequence enforceOrder;
2368  auto req = getGetRequest();
2369  auto handler = openTransaction();
2370 
2371  int streamID = handler->txn_->getID();
2372  int pushID = streamID + 1;
2373  int badAssocID = streamID + 2;
2374 
2375  EXPECT_CALL(*codecPtr_,
2376  generateRstStream(_, pushID, ErrorCode::PROTOCOL_ERROR));
2377  EXPECT_CALL(*codecPtr_,
2378  generateRstStream(_, pushID, ErrorCode::_SPDY_INVALID_STREAM))
2379  .Times(2);
2380 
2381  auto resp = makeResponse(200);
2382  codecCb_->onPushMessageBegin(pushID, badAssocID, resp.get());
2383  codecCb_->onHeadersComplete(pushID, std::move(resp));
2384  codecCb_->onMessageComplete(pushID, false);
2385 
2386  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2387  EXPECT_FALSE(msg->getIsUpgraded());
2388  EXPECT_EQ(200, msg->getStatusCode());
2389  });
2390  handler->expectEOM();
2391 
2392  resp = makeResponse(200);
2393  codecCb_->onMessageBegin(streamID, resp.get());
2394  codecCb_->onHeadersComplete(streamID, std::move(resp));
2395  codecCb_->onMessageComplete(streamID, false);
2396 
2397  // Cleanup
2398  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID, _));
2399  EXPECT_CALL(*handler, detachTransaction());
2400  handler->terminate();
2401 
2402  EXPECT_TRUE(!httpSession_->hasActiveTransactions());
2403  httpSession_->destroy();
2404 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
uint32_t streamID
Definition: SPDYCodec.cpp:131
TEST_F ( MockHTTP2UpstreamTest  ,
ServerPushAfterFin   
)

Definition at line 2406 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::getGetRequest(), handler(), testing::InvokeWithoutArgs(), proxygen::makeResponse(), folly::gen::move, and streamID.

2406  {
2407  // Test that protocol error is generated on server push
2408  // after FIN is received on regular response on the stream
2409  InSequence enforceOrder;
2410  auto req = getGetRequest();
2411  auto handler = openTransaction();
2412 
2413  int streamID = handler->txn_->getID();
2414  int pushID = streamID + 1;
2415 
2416  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2417  EXPECT_FALSE(msg->getIsUpgraded());
2418  EXPECT_EQ(200, msg->getStatusCode());
2419  });
2420  handler->expectEOM();
2421 
2422  auto resp = makeResponse(200);
2423  codecCb_->onMessageBegin(streamID, resp.get());
2424  codecCb_->onHeadersComplete(streamID, std::move(resp));
2425  codecCb_->onMessageComplete(streamID, false);
2426 
2427  EXPECT_CALL(*codecPtr_,
2428  generateRstStream(_, pushID, ErrorCode::PROTOCOL_ERROR))
2429  .WillOnce(InvokeWithoutArgs([this] {
2430  // Verify that the assoc txn is still present
2431  EXPECT_TRUE(httpSession_->hasActiveTransactions());
2432  return 1;
2433  }));
2434  EXPECT_CALL(*codecPtr_,
2435  generateRstStream(_, pushID, ErrorCode::_SPDY_INVALID_STREAM))
2436  .Times(2);
2437 
2438  resp = makeResponse(200);
2439  codecCb_->onPushMessageBegin(pushID, streamID, resp.get());
2440  codecCb_->onHeadersComplete(pushID, std::move(resp));
2441  codecCb_->onMessageComplete(pushID, false);
2442 
2443  // Cleanup
2444  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID, _));
2445  EXPECT_CALL(*handler, detachTransaction());
2446  handler->terminate();
2447 
2448  EXPECT_TRUE(!httpSession_->hasActiveTransactions());
2449  httpSession_->destroy();
2450 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
void handler(int, siginfo_t *, void *)
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
uint32_t streamID
Definition: SPDYCodec.cpp:131
TEST_F ( MockHTTP2UpstreamTest  ,
ServerPushHandlerInstallFail   
)

Definition at line 2452 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::getGetRequest(), handler(), testing::Invoke(), folly::gen::move, proxygen::HTTPTransaction::setHandler(), and streamID.

2452  {
2453  // Test that REFUSED_STREAM error is generated when the session
2454  // fails to install the server push handler
2455  InSequence enforceOrder;
2456  auto req = getGetRequest();
2457  auto handler = openTransaction();
2458 
2459  int streamID = handler->txn_->getID();
2460  int pushID = streamID + 1;
2461 
2462  EXPECT_CALL(*handler, onPushedTransaction(_))
2463  .WillOnce(Invoke([] (HTTPTransaction* txn) {
2464  // Intentionally unset the handler on the upstream push txn
2465  txn->setHandler(nullptr);
2466  }));
2467  EXPECT_CALL(*codecPtr_,
2468  generateRstStream(_, pushID, ErrorCode::REFUSED_STREAM));
2469  EXPECT_CALL(*codecPtr_,
2470  generateRstStream(_, pushID, ErrorCode::_SPDY_INVALID_STREAM))
2471  .Times(2);
2472 
2473  auto resp = std::make_unique<HTTPMessage>();
2474  resp->setStatusCode(200);
2475  resp->setStatusMessage("OK");
2476  codecCb_->onPushMessageBegin(pushID, streamID, resp.get());
2477  codecCb_->onHeadersComplete(pushID, std::move(resp));
2478  codecCb_->onMessageComplete(pushID, false);
2479 
2480  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2481  EXPECT_FALSE(msg->getIsUpgraded());
2482  EXPECT_EQ(200, msg->getStatusCode());
2483  });
2484  handler->expectEOM();
2485 
2486  resp = std::make_unique<HTTPMessage>();
2487  resp->setStatusCode(200);
2488  resp->setStatusMessage("OK");
2489  codecCb_->onMessageBegin(streamID, resp.get());
2490  codecCb_->onHeadersComplete(streamID, std::move(resp));
2491  codecCb_->onMessageComplete(streamID, false);
2492 
2493  // Cleanup
2494  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID, _));
2495  EXPECT_CALL(*handler, detachTransaction());
2496  handler->terminate();
2497 
2498  EXPECT_TRUE(!httpSession_->hasActiveTransactions());
2499  httpSession_->destroy();
2500 }
virtual void setHandler(Handler *handler)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
uint32_t streamID
Definition: SPDYCodec.cpp:131
TEST_F ( MockHTTP2UpstreamTest  ,
ServerPushUnhandledAssoc   
)

Definition at line 2502 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, EXPECT_TRUE, proxygen::getGetRequest(), handler(), folly::gen::move, and streamID.

2502  {
2503  // Test that REFUSED_STREAM error is generated when the assoc txn
2504  // is unhandled
2505  InSequence enforceOrder;
2506  auto req = getGetRequest();
2507  auto handler = openTransaction();
2508 
2509  int streamID = handler->txn_->getID();
2510  int pushID = streamID + 1;
2511 
2512  // Forcefully unset the handler on the assoc txn
2513  handler->txn_->setHandler(nullptr);
2514 
2515  EXPECT_CALL(*codecPtr_,
2516  generateRstStream(_, pushID, ErrorCode::REFUSED_STREAM));
2517  EXPECT_CALL(*codecPtr_,
2518  generateRstStream(_, pushID, ErrorCode::_SPDY_INVALID_STREAM))
2519  .Times(2);
2520 
2521  auto resp = std::make_unique<HTTPMessage>();
2522  resp->setStatusCode(200);
2523  resp->setStatusMessage("OK");
2524  codecCb_->onPushMessageBegin(pushID, streamID, resp.get());
2525  codecCb_->onHeadersComplete(pushID, std::move(resp));
2526  codecCb_->onMessageComplete(pushID, false);
2527 
2528  // Cleanup
2529  EXPECT_CALL(*codecPtr_, generateRstStream(_, streamID, _));
2530  handler->terminate();
2531 
2532  EXPECT_TRUE(!httpSession_->hasActiveTransactions());
2533  httpSession_->destroy();
2534 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
uint32_t streamID
Definition: SPDYCodec.cpp:131
TEST_F ( MockHTTPUpstreamTest  ,
HeadersThenBodyThenHeaders   
)

Definition at line 2536 of file HTTPUpstreamSessionTest.cpp.

References testing::_, ASSERT_EQ, EXPECT_CALL, EXPECT_EQ, EXPECT_TRUE, proxygen::getGetRequest(), proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorIngressStateTransition, makeBuf(), proxygen::makeResponse(), folly::gen::move, string, and proxygen::Exception::what().

2536  {
2537  HTTPMessage req = getGetRequest();
2538  auto handler = openTransaction();
2539  handler->txn_->sendHeaders(req);
2540 
2541  handler->expectHeaders();
2542  EXPECT_CALL(*handler, onBody(_));
2543  // After getting the second headers, transaction will detach the handler
2544  handler->expectError([&] (const HTTPException& err) {
2547  ASSERT_EQ("Invalid ingress state transition, state=RegularBodyReceived, "
2548  "event=onHeaders, streamID=1",
2549  std::string(err.what()));
2550  });
2551  handler->expectDetachTransaction();
2552  auto resp = makeResponse(200);
2553  codecCb_->onMessageBegin(1, resp.get());
2554  codecCb_->onHeadersComplete(1, std::move(resp));
2555  codecCb_->onBody(1, makeBuf(20), 0);
2556  // Now receive headers again, on the same stream (illegal!)
2557  codecCb_->onHeadersComplete(1, makeResponse(200));
2558  eventBase_.loop();
2559 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
std::unique_ptr< HTTPMessage > makeResponse(uint16_t statusCode)
Definition: TestUtils.cpp:147
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( MockHTTP2UpstreamTest  ,
DelayUpstreamWindowUpdate   
)

Definition at line 2561 of file HTTPUpstreamSessionTest.cpp.

References testing::_, EXPECT_CALL, proxygen::getGetRequest(), handler(), and testing::Return().

2561  {
2562  EXPECT_CALL(*codecPtr_, supportsStreamFlowControl())
2563  .WillRepeatedly(Return(true));
2564 
2565  auto handler = openTransaction();
2566  handler->txn_->setReceiveWindow(1000000); // One miiiillion
2567 
2568  InSequence enforceOrder;
2569  EXPECT_CALL(*codecPtr_, generateHeader(_, _, _, _, _));
2570  EXPECT_CALL(*codecPtr_, generateWindowUpdate(_, _, _));
2571 
2572  HTTPMessage req = getGetRequest();
2573  handler->txn_->sendHeaders(req);
2574  handler->expectDetachTransaction();
2575  handler->txn_->sendAbort();
2576  httpSession_->destroy();
2577 }
void handler(int, siginfo_t *, void *)
HTTPMessage getGetRequest(const std::string &url)
Definition: TestUtils.cpp:76
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
internal::ReturnAction< R > Return(R value)
TEST_F ( MockHTTPUpstreamTest  ,
ForceShutdownInSetTransaction   
)

Definition at line 2579 of file HTTPUpstreamSessionTest.cpp.

References ASSERT_EQ, EXPECT_EQ, EXPECT_TRUE, proxygen::Exception::getProxygenError(), handler(), proxygen::Exception::hasProxygenError(), proxygen::kErrorDropped, string, and proxygen::Exception::what().

2579  {
2581  handler.expectTransaction([&] (HTTPTransaction* txn) {
2582  handler.txn_ = txn;
2583  httpSession_->dropConnection();
2584  });
2585  handler.expectError([&] (const HTTPException& err) {
2588  ASSERT_EQ(folly::to<std::string>("Dropped on transaction id: ",
2589  handler.txn_->getID()),
2590  std::string(err.what()));
2591  });
2592  handler.expectDetachTransaction();
2593  (void)httpSession_->newTransaction(&handler);
2594 }
ProxygenError getProxygenError() const
Definition: Exception.h:50
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void handler(int, siginfo_t *, void *)
bool hasProxygenError() const
Definition: Exception.h:44
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
const char * string
Definition: Conv.cpp:212
const char * what(void) const noexceptoverride
Definition: Exception.cpp:26
TEST_F ( HTTP2UpstreamSessionTest  ,
TestReplaySafetyCallback   
)

Definition at line 2596 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_CALL, ON_CALL, testing::Return(), and transport_.

2596  {
2597  auto sock = dynamic_cast<HTTPTransaction::Transport*>(httpSession_);
2598 
2602 
2603  EXPECT_CALL(*transport_, isReplaySafe())
2604  .WillRepeatedly(Return(false));
2605  sock->addWaitingForReplaySafety(&cb1);
2606  sock->addWaitingForReplaySafety(&cb2);
2607  sock->addWaitingForReplaySafety(&cb3);
2608  sock->removeWaitingForReplaySafety(&cb2);
2609 
2610  ON_CALL(*transport_, isReplaySafe())
2611  .WillByDefault(Return(true));
2612  EXPECT_CALL(cb1, onReplaySafe_());
2613  EXPECT_CALL(cb3, onReplaySafe_());
2614  replaySafetyCallback_->onReplaySafe();
2615 
2616  httpSession_->destroy();
2617 }
#define ON_CALL(obj, call)
AsyncFizzClient::UniquePtr transport_
#define EXPECT_CALL(obj, call)
internal::ReturnAction< R > Return(R value)
TEST_F ( HTTP2UpstreamSessionTest  ,
TestAlreadyReplaySafe   
)

Definition at line 2619 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_CALL, testing::Return(), and transport_.

2619  {
2620  auto sock = dynamic_cast<HTTPTransaction::Transport*>(httpSession_);
2621 
2623 
2624  EXPECT_CALL(*transport_, isReplaySafe())
2625  .WillRepeatedly(Return(true));
2626  EXPECT_CALL(cb, onReplaySafe_());
2627  sock->addWaitingForReplaySafety(&cb);
2628 
2629  httpSession_->destroy();
2630 }
AsyncFizzClient::UniquePtr transport_
#define EXPECT_CALL(obj, call)
internal::ReturnAction< R > Return(R value)
TEST_F ( HTTP2UpstreamSessionTest  ,
TestChainedBufIngress   
)

Definition at line 2632 of file HTTPUpstreamSessionTest.cpp.

References testing::_, folly::IOBuf::copyBuffer(), EXPECT_CALL, and folly::gen::move.

2632  {
2633  auto buf = folly::IOBuf::copyBuffer("hi");
2634  buf->prependChain(folly::IOBuf::copyBuffer("hello"));
2635 
2637  this->httpSession_->setInfoCallback(&infoCb);
2638 
2639  EXPECT_CALL(infoCb, onRead(_, 7));
2640  readCallback_->readBufferAvailable(std::move(buf));
2641 
2642  httpSession_->destroy();
2643 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
TEST_F ( HTTP2UpstreamSessionTest  ,
AttachDetach   
)

Definition at line 2645 of file HTTPUpstreamSessionTest.cpp.

References folly::IOBufQueue::cacheChainLength(), folly::HHWheelTimer::DEFAULT_TICK_INTERVAL, EXPECT_EQ, handler(), i, folly::TimeoutManager::INTERNAL, folly::EventBase::loopOnce(), makeBuf(), makeServerCodec(), folly::IOBufQueue::move(), folly::HHWheelTimer::newTimer(), gmock_output_test::output, REGISTER_TYPED_TEST_CASE_P(), proxygen::HTTPMessage::setStatusCode(), and uint64_t.

2645  {
2646  folly::EventBase base;
2647  auto timer =
2649  &base,
2650  std::chrono::milliseconds(folly::HHWheelTimer::DEFAULT_TICK_INTERVAL),
2651  TimeoutManager::InternalEnum::INTERNAL, std::chrono::milliseconds(500));
2652  WheelTimerInstance timerInstance(timer.get());
2653  uint64_t filterCount = 0;
2654  auto fn = [&filterCount](HTTPCodecFilter* /*filter*/) { filterCount++; };
2655 
2656  InSequence enforceOrder;
2657  auto egressCodec = makeServerCodec();
2659  egressCodec->generateConnectionPreface(output);
2660  egressCodec->generateSettings(output);
2661 
2662  for (auto i = 0; i < 2; i++) {
2663  auto handler = openTransaction();
2664  handler->expectHeaders([&] (std::shared_ptr<HTTPMessage> msg) {
2665  EXPECT_EQ(200, msg->getStatusCode());
2666  });
2667  handler->expectBody();
2668  handler->expectEOM();
2669  handler->expectDetachTransaction();
2670 
2671  HTTPMessage resp;
2672  resp.setStatusCode(200);
2673  egressCodec->generateHeader(output, handler->txn_->getID(), resp);
2674  egressCodec->generateBody(output, handler->txn_->getID(), makeBuf(20),
2675  HTTPCodec::NoPadding, true /* eom */);
2676 
2677  handler->sendRequest();
2678  auto buf = output.move();
2679  buf->coalesce();
2680  readAndLoop(buf.get());
2681 
2682  httpSession_->detachThreadLocals();
2683  httpSession_->attachThreadLocals(&base, nullptr, timerInstance, nullptr, fn,
2684  nullptr, nullptr);
2685  EXPECT_EQ(filterCount, 2);
2686  filterCount = 0;
2687  base.loopOnce();
2688  }
2689  httpSession_->destroy();
2690 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static int DEFAULT_TICK_INTERVAL
Definition: HHWheelTimer.h:163
void handler(int, siginfo_t *, void *)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
static UniquePtr newTimer(Args &&...args)
Definition: HHWheelTimer.h:61
static Options cacheChainLength()
Definition: IOBufQueue.h:83
bool loopOnce(int flags=0)
Definition: EventBase.cpp:271
std::enable_if< std::is_enum< Version >::value, std::unique_ptr< MyCodec > >::type makeServerCodec(Version version)
void setStatusCode(uint16_t status)
TYPED_TEST_CASE_P ( HTTPUpstreamTest  )
TYPED_TEST_P ( HTTPUpstreamTest  ,
ImmediateEof   
)

Definition at line 1020 of file HTTPUpstreamSessionTest.cpp.

References EXPECT_EQ.

1020  {
1021  // Receive an EOF without any request data
1022  this->readCallback_->readEOF();
1023  this->eventBase_.loop();
1024  EXPECT_EQ(this->sessionDestroyed_, true);
1025 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922