Skip to content

Commit

Permalink
port test_body_size_limit to C++
Browse files Browse the repository at this point in the history
Summary: This was a prospect test that now needs finer grain control.  This exposed some HTTP/2 bugs and also an ancient bug in TestAsyncTransport.

Test Plan: Unit tests

Reviewed By: [email protected]

Subscribers: doug, bmatheny

FB internal diff: D1855310

Signature: t1:1855310:1424834240:8269b774e276d54beccfcb4e46f9120c8e10e1bd
  • Loading branch information
afrind authored and viswanathgs committed Mar 6, 2015
1 parent b36d031 commit ce6f344
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
64 changes: 62 additions & 2 deletions proxygen/lib/http/session/test/HTTPDownstreamSessionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ TEST_F(HTTPDownstreamSessionTest, body_packetization) {
EXPECT_CALL(handler1, onHeadersComplete(_));
EXPECT_CALL(handler1, onEOM())
.WillOnce(InvokeWithoutArgs([&handler1, this] {
handler1.sendReplyWithBody(200, 100);
handler1.sendReplyWithBody(200, 32768);
}));
EXPECT_CALL(handler1, detachTransaction());

Expand Down Expand Up @@ -1510,6 +1510,66 @@ TYPED_TEST_P(HTTPDownstreamTest, testWritesDraining) {
this->eventBase_.loop();
}

TYPED_TEST_P(HTTPDownstreamTest, testBodySizeLimit) {
IOBufQueue requests;
HTTPMessage req = getGetRequest();
auto clientCodec =
makeClientCodec<typename TypeParam::Codec>(TypeParam::version);
auto streamID = HTTPCodec::StreamID(1);
clientCodec->generateConnectionPreface(requests);
clientCodec->generateHeader(requests, streamID, req);
clientCodec->generateEOM(requests, streamID);
streamID += 2;
clientCodec->generateHeader(requests, streamID, req, 0);
clientCodec->generateEOM(requests, streamID);
MockHTTPHandler handler1;
MockHTTPHandler handler2;

EXPECT_CALL(this->mockController_, getRequestHandler(_, _))
.WillOnce(Return(&handler1))
.WillOnce(Return(&handler2));

InSequence handlerSequence;
EXPECT_CALL(handler1, setTransaction(_))
.WillOnce(Invoke([&handler1] (HTTPTransaction* txn) {
handler1.txn_ = txn; }));
EXPECT_CALL(handler1, onHeadersComplete(_));
EXPECT_CALL(handler1, onEOM());
EXPECT_CALL(handler2, setTransaction(_))
.WillOnce(Invoke([&handler2] (HTTPTransaction* txn) {
handler2.txn_ = txn; }));
EXPECT_CALL(handler2, onHeadersComplete(_));
EXPECT_CALL(handler2, onEOM())
.WillOnce(InvokeWithoutArgs([&] {
handler1.sendReplyWithBody(200, 5000);
handler2.sendReplyWithBody(200, 5000);
}));
EXPECT_CALL(handler1, detachTransaction());
EXPECT_CALL(handler2, detachTransaction());

this->transport_->addReadEvent(requests, std::chrono::milliseconds(10));
this->transport_->startReadEvents();
this->eventBase_.loop();

NiceMock<MockHTTPCodecCallback> callbacks;

std::list<HTTPCodec::StreamID> streams;
EXPECT_CALL(callbacks, onMessageBegin(1, _));
EXPECT_CALL(callbacks, onHeadersComplete(1, _));
EXPECT_CALL(callbacks, onMessageBegin(3, _));
EXPECT_CALL(callbacks, onHeadersComplete(3, _));
EXPECT_CALL(callbacks, onBody(1, _));
EXPECT_CALL(callbacks, onBody(3, _));
EXPECT_CALL(callbacks, onBody(1, _));
EXPECT_CALL(callbacks, onMessageComplete(1, _));
EXPECT_CALL(callbacks, onBody(3, _));
EXPECT_CALL(callbacks, onMessageComplete(3, _));

clientCodec->setCallback(&callbacks);
this->parseOutput(*clientCodec);

}

// Set max streams=1
// send two spdy requests a few ms apart.
// Block writes
Expand Down Expand Up @@ -1572,7 +1632,7 @@ TEST_F(SPDY3DownstreamSessionTest, spdy_max_concurrent_streams) {
}

REGISTER_TYPED_TEST_CASE_P(HTTPDownstreamTest,
testWritesDraining);
testWritesDraining, testBodySizeLimit);

typedef ::testing::Types<SPDY2CodecPair, SPDY3CodecPair, SPDY3_1CodecPair,
HTTP2CodecPair> ParallelCodecs;
Expand Down
2 changes: 1 addition & 1 deletion proxygen/lib/test/TestAsyncTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ TestAsyncTransport::writeChain(AsyncTransportWrapper::WriteCallback* callback,
const IOBuf* next = head;
unsigned i = 0;
do {
vec[i].iov_base = const_cast<uint8_t *>(next->buffer());
vec[i].iov_base = const_cast<uint8_t *>(next->data());
vec[i++].iov_len = next->length();
next = next->next();
} while (next != head);
Expand Down

0 comments on commit ce6f344

Please sign in to comment.