Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test case for stream reset during delay injection #354

Merged
merged 2 commits into from
Jan 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 40 additions & 18 deletions test/common/http/filter/fault_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ TEST_F(FaultFilterTest, AbortWithHttpStatus) {

// Delay related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 0))
.Times(1)
.WillOnce(Return(false));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", _)).Times(0);
Expand All @@ -205,11 +204,9 @@ TEST_F(FaultFilterTest, AbortWithHttpStatus) {

// Abort related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", 429))
.Times(1)
.WillOnce(Return(429));

Http::TestHeaderMapImpl response_headers{{":status", "429"}};
Expand All @@ -231,17 +228,14 @@ TEST_F(FaultFilterTest, FixedDelayZeroDuration) {

// Delay related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 100))
.Times(1)
.WillOnce(Return(true));

// Return 0ms delay
EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.Times(1)
.WillOnce(Return(0));

// Abort related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", 0))
.Times(1)
.WillOnce(Return(false));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", _)).Times(0);
Expand All @@ -263,11 +257,9 @@ TEST_F(FaultFilterTest, FixedDelayNonZeroDuration) {

// Delay related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.Times(1)
.WillOnce(Return(5000UL));

SCOPED_TRACE("FixedDelayNonZeroDuration");
Expand All @@ -279,15 +271,14 @@ TEST_F(FaultFilterTest, FixedDelayNonZeroDuration) {

// Abort related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", 0))
.Times(1)
.WillOnce(Return(false));

// Delay only case
EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", _)).Times(0);
EXPECT_CALL(filter_callbacks_, encodeHeaders_(_, _)).Times(0);
EXPECT_CALL(filter_callbacks_.request_info_,
setResponseFlag(Http::AccessLog::ResponseFlag::FaultInjected)).Times(0);
EXPECT_CALL(filter_callbacks_, continueDecoding()).Times(1);
EXPECT_CALL(filter_callbacks_, continueDecoding());
timer_->callback_();

EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, false));
Expand All @@ -302,11 +293,9 @@ TEST_F(FaultFilterTest, FixedDelayAndAbort) {

// Delay related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.Times(1)
.WillOnce(Return(5000UL));

SCOPED_TRACE("FixedDelayAndAbort");
Expand All @@ -319,11 +308,9 @@ TEST_F(FaultFilterTest, FixedDelayAndAbort) {

// Abort related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", 503))
.Times(1)
.WillOnce(Return(503));

Http::TestHeaderMapImpl response_headers{{":status", "503"}};
Expand All @@ -350,11 +337,9 @@ TEST_F(FaultFilterTest, FixedDelayAndAbortHeaderMatchSuccess) {

// Delay related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.Times(1)
.WillOnce(Return(5000UL));

SCOPED_TRACE("FixedDelayAndAbortHeaderMatchSuccess");
Expand All @@ -367,11 +352,9 @@ TEST_F(FaultFilterTest, FixedDelayAndAbortHeaderMatchSuccess) {

// Abort related calls
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", 100))
.Times(1)
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", 503))
.Times(1)
.WillOnce(Return(503));

Http::TestHeaderMapImpl response_headers{{":status", "503"}};
Expand Down Expand Up @@ -413,4 +396,43 @@ TEST_F(FaultFilterTest, FixedDelayAndAbortHeaderMatchFail) {
EXPECT_EQ(0UL, config_->stats().aborts_injected_.value());
}

TEST_F(FaultFilterTest, TimerResetAfterStreamReset) {
SetUpTest(fixed_delay_only_json);

// Prep up with a 5s delay
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.delay.fixed_delay_percent", 100))
.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.WillOnce(Return(5000UL));

SCOPED_TRACE("FixedDelayWithStreamReset");
timer_ = new Event::MockTimer(&filter_callbacks_.dispatcher_);
EXPECT_CALL(*timer_, enableTimer(std::chrono::milliseconds(5000UL)));

EXPECT_CALL(filter_callbacks_.request_info_,
setResponseFlag(Http::AccessLog::ResponseFlag::DelayInjected));

EXPECT_EQ(0UL, config_->stats().delays_injected_.value());

EXPECT_EQ(FilterHeadersStatus::StopIteration, filter_->decodeHeaders(request_headers_, false));

// delay timer should have been fired by now. If caller resets the stream while we are waiting
// on the delay timer, check if timers are cancelled
EXPECT_CALL(*timer_, disableTimer());

// The timer callback should never be called.
EXPECT_CALL(runtime_.snapshot_, featureEnabled("fault.http.abort.abort_percent", _)).Times(0);
EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.abort.http_status", _)).Times(0);
EXPECT_CALL(filter_callbacks_, encodeHeaders_(_, _)).Times(0);
EXPECT_CALL(filter_callbacks_.request_info_,
setResponseFlag(Http::AccessLog::ResponseFlag::FaultInjected)).Times(0);
EXPECT_CALL(filter_callbacks_, continueDecoding()).Times(0);
EXPECT_EQ(0UL, config_->stats().aborts_injected_.value());

EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though it works from a "test this thing" perspective, this is not a totally realistic test case. What you are doing here is calling decodeData with end_stream = true. This means that the request is over, as such it's impossible for decodeTrailers() to be called, so I would delete line 453. FYI, it is possible for resetStream callback to get called even when request is complete, since downstream can reset waiting for a response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. fixed the code and removed the silly .Times(1) from all tests. Thanks for the feedback!


filter_callbacks_.reset_callback_();
}

} // Http