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 1 commit
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
42 changes: 42 additions & 0 deletions test/common/http/filter/fault_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,46 @@ 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))
.Times(1)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Times(1) is implied when you do .WillOnce() or just a plain expect_call, so can typically be removed. There are multiple cases in here where this applies.

.WillOnce(Return(true));

EXPECT_CALL(runtime_.snapshot_, getInteger("fault.http.delay.fixed_duration_ms", 5000))
.Times(1)
.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)).Times(1);

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!

EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_headers_));

filter_callbacks_.reset_callback_();
}

} // Http