proxygen
FilterTests.cpp File Reference

Go to the source code of this file.

Classes

class  MockFlowControlCallback
 
class  FilterTest
 
class  HTTPChecksTest
 
class  FlowControlFilterTest< initSize >
 

Typedefs

using DefaultFlowControl = FlowControlFilterTest< 0 >
 
using BigWindow = FlowControlFilterTest< 1000000 >
 

Functions

 MATCHER (IsFlowException,"")
 
 TEST_F (DefaultFlowControl, FlowControlConstruct)
 
 TEST_F (DefaultFlowControl, SendUpdate)
 
 TEST_F (BigWindow, RecvTooMuch)
 
 TEST_F (BigWindow, RemoteIncrease)
 
 TEST_F (HTTPChecksTest, SendTraceBodyDeath)
 
 TEST_F (HTTPChecksTest, SendGetBody)
 
 TEST_F (HTTPChecksTest, RecvTraceBody)
 

Typedef Documentation

using BigWindow = FlowControlFilterTest<1000000>

Definition at line 100 of file FilterTests.cpp.

Definition at line 99 of file FilterTests.cpp.

Function Documentation

MATCHER ( IsFlowException  ,
""   
)

Definition at line 102 of file FilterTests.cpp.

References proxygen::FLOW_CONTROL_ERROR.

102  {
103  return arg->hasCodecStatusCode() &&
104  arg->getCodecStatusCode() == ErrorCode::FLOW_CONTROL_ERROR &&
105  !arg->hasHttpStatusCode() &&
106  !arg->hasProxygenError();
107 }
TEST_F ( DefaultFlowControl  ,
FlowControlConstruct   
)

Definition at line 109 of file FilterTests.cpp.

References ASSERT_EQ, EXPECT_CALL, EXPECT_DEATH_NO_CORE, proxygen::makeBuf(), and proxygen::HTTPCodec::NoPadding.

109  {
110  // Constructing the filter with a low capacity defaults to kInitialCapacity
111  // initial capacity, so no window update should have been generated in
112  // the constructor
113  InSequence enforceSequence;
114  ASSERT_EQ(writeBuf_.chainLength(), 0);
115 
116  // Our send window is limited to kInitialCapacity
117  chain_->generateBody(writeBuf_, 1,
118  makeBuf(kInitialCapacity - 1),
119  HTTPCodec::NoPadding, false);
120 
121  // the window isn't full yet, so getting a window update shouldn't give a
122  // callback informing us that it is open again
123  callbackStart_->onWindowUpdate(0, 1);
124 
125  // Now fill the window (2 more bytes)
126  EXPECT_CALL(flowCallback_, onConnectionSendWindowClosed());
127  chain_->generateBody(writeBuf_, 1, makeBuf(2), HTTPCodec::NoPadding, false);
128  // get the callback informing the window is open once we get a window update
129  EXPECT_CALL(flowCallback_, onConnectionSendWindowOpen());
130  callbackStart_->onWindowUpdate(0, 1);
131 
132  // Overflowing the window is fatal. Write 2 bytes (only 1 byte left in window)
133  EXPECT_DEATH_NO_CORE(chain_->generateBody(writeBuf_, 1, makeBuf(2),
134  HTTPCodec::NoPadding, false),
135  ".*");
136 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_DEATH_NO_CORE(token, regex)
Definition: TestUtils.h:19
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
#define EXPECT_CALL(obj, call)
TEST_F ( DefaultFlowControl  ,
SendUpdate   
)

Definition at line 138 of file FilterTests.cpp.

References testing::_, callback_, codec_, EXPECT_CALL, proxygen::makeBuf(), and testing::Return().

138  {
139  // Make sure we send a window update when the window decreases below half
140  InSequence enforceSequence;
141  EXPECT_CALL(callback_, onBody(_, _, _))
142  .WillRepeatedly(Return());
143 
144  // Have half the window outstanding
145  callbackStart_->onBody(1, makeBuf(kInitialCapacity / 2 + 1), 0);
146  filter_->ingressBytesProcessed(writeBuf_, kInitialCapacity / 2);
147 
148  // It should wait until the "+1" is ack'd to generate the coallesced update
150  generateWindowUpdate(_, 0, kInitialCapacity / 2 + 1));
151  filter_->ingressBytesProcessed(writeBuf_, 1);
152 }
std::unique_ptr< Codec > codec_
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
folly::Function< void()> callback_
internal::ReturnAction< R > Return(R value)
TEST_F ( BigWindow  ,
RecvTooMuch   
)

Definition at line 154 of file FilterTests.cpp.

References testing::_, ASSERT_EQ, ASSERT_FALSE, ASSERT_GT, ASSERT_TRUE, callback_, EXPECT_CALL, testing::Invoke(), proxygen::makeBuf(), and string.

154  {
155  // Constructing the filter with a large capacity causes a WINDOW_UPDATE
156  // for stream zero to be generated
157  ASSERT_GT(writeBuf_.chainLength(), 0);
158 
159  InSequence enforceSequence;
160  EXPECT_CALL(callback_, onBody(_, _, _));
161  EXPECT_CALL(callback_, onError(0, IsFlowException(), _))
162  .WillOnce(Invoke([](HTTPCodec::StreamID,
163  std::shared_ptr<HTTPException> exc,
164  bool /*newTxn*/) {
165  ASSERT_EQ(
166  "Failed to reserve receive window, window size=0, "
167  "amount=1",
168  std::string(exc->what()));
169  }));
170 
171  // Receive the max amount advertised
172  callbackStart_->onBody(1, makeBuf(recvWindow_), 0);
173  ASSERT_TRUE(chain_->isReusable());
174  // Receive 1 byte too much
175  callbackStart_->onBody(1, makeBuf(1), 0);
176  ASSERT_FALSE(chain_->isReusable());
177 }
#define ASSERT_GT(val1, val2)
Definition: gtest.h:1976
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
folly::Function< void()> callback_
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST_F ( BigWindow  ,
RemoteIncrease   
)

Definition at line 179 of file FilterTests.cpp.

References testing::_, ASSERT_EQ, ASSERT_FALSE, callback_, EXPECT_CALL, testing::Invoke(), proxygen::makeBuf(), max, proxygen::HTTPCodec::NoPadding, and string.

179  {
180  // The remote side sends us a window update for stream=0, increasing our
181  // available window
182  InSequence enforceSequence;
183 
184  ASSERT_EQ(filter_->getAvailableSend(), kInitialCapacity);
185  callbackStart_->onWindowUpdate(0, 10);
186  ASSERT_EQ(filter_->getAvailableSend(), kInitialCapacity + 10);
187 
188  EXPECT_CALL(flowCallback_, onConnectionSendWindowClosed());
189  chain_->generateBody(writeBuf_, 1,
190  makeBuf(kInitialCapacity + 10),
191  HTTPCodec::NoPadding, false);
192  ASSERT_EQ(filter_->getAvailableSend(), 0);
193 
194  // Now the remote side sends a HUGE update (just barely legal)
195  // Since the window was full, this generates a callback from the filter
196  // telling us the window is no longer full.
197  EXPECT_CALL(flowCallback_, onConnectionSendWindowOpen());
198  callbackStart_->onWindowUpdate(0, std::numeric_limits<int32_t>::max());
199  ASSERT_EQ(filter_->getAvailableSend(), std::numeric_limits<int32_t>::max());
200 
201  // Now overflow it by 1
202  EXPECT_CALL(callback_, onError(0, IsFlowException(), _))
203  .WillOnce(Invoke([](HTTPCodec::StreamID,
204  std::shared_ptr<HTTPException> exc,
205  bool /*newTxn*/) {
206  ASSERT_EQ(
207  "Failed to update send window, outstanding=0, "
208  "amount=1",
209  std::string(exc->what()));
210  }));
211  callbackStart_->onWindowUpdate(0, 1);
212  ASSERT_FALSE(chain_->isReusable());
213 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogLevel max
Definition: LogLevel.cpp:31
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
Definition: ZlibTests.cpp:26
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
const char * string
Definition: Conv.cpp:212
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
folly::Function< void()> callback_
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
TEST_F ( HTTPChecksTest  ,
SendTraceBodyDeath   
)

Definition at line 215 of file FilterTests.cpp.

References EXPECT_DEATH_NO_CORE, proxygen::getPostRequest(), and proxygen::HTTPMessage::setMethod().

215  {
216  // It is NOT allowed to send a TRACE with a body.
217 
218  HTTPMessage msg = getPostRequest();
219  msg.setMethod("TRACE");
220 
221  EXPECT_DEATH_NO_CORE(chain_->generateHeader(writeBuf_, 0, msg), ".*");
222 }
#define EXPECT_DEATH_NO_CORE(token, regex)
Definition: TestUtils.h:19
void setMethod(HTTPMethod method)
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
TEST_F ( HTTPChecksTest  ,
SendGetBody   
)

Definition at line 224 of file FilterTests.cpp.

References testing::_, codec_, EXPECT_CALL, proxygen::getPostRequest(), and proxygen::HTTPMessage::setMethod().

224  {
225  // It is allowed to send a GET with a content-length. It is up to the
226  // server to ignore it.
227 
228  EXPECT_CALL(*codec_, generateHeader(_, _, _, _, _));
229 
230  HTTPMessage msg = getPostRequest();
231  msg.setMethod("GET");
232 
233  chain_->generateHeader(writeBuf_, 0, msg);
234 }
std::unique_ptr< Codec > codec_
void setMethod(HTTPMethod method)
HTTPMessage getPostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:102
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
TEST_F ( HTTPChecksTest  ,
RecvTraceBody   
)

Definition at line 236 of file FilterTests.cpp.

References testing::_, ASSERT_EQ, ASSERT_TRUE, callback_, EXPECT_CALL, testing::Invoke(), proxygen::makePostRequest(), and folly::gen::move.

236  {
237  // In proxygen, we deal with receiving a TRACE with a body by 400'ing it
238 
239  EXPECT_CALL(callback_, onError(_, _, _))
240  .WillOnce(Invoke([] (HTTPCodec::StreamID,
241  std::shared_ptr<HTTPException> exc,
242  bool newTxn) {
243  ASSERT_TRUE(newTxn);
244  ASSERT_EQ(exc->getHttpStatusCode(), 400);
245  ASSERT_EQ(0,
246  strcmp("RFC2616: Request Body Not Allowed",
247  exc->what()));
248  }));
249 
250  auto msg = makePostRequest();
251  msg->setMethod("TRACE");
252 
253  callbackStart_->onHeadersComplete(0, std::move(msg));
254 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< HTTPMessage > makePostRequest(uint32_t contentLength)
Definition: TestUtils.cpp:124
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_CALL(obj, call)
uint64_t StreamID
Definition: HTTPCodec.h:49
const internal::AnythingMatcher _
folly::Function< void()> callback_
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865