From 8b076486998fa1dc2110461f64814dbad7416a48 Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Sun, 15 Jan 2017 15:08:07 -0500 Subject: [PATCH 1/2] add test case for stream reset during delay injection --- test/common/http/filter/fault_filter_test.cc | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/common/http/filter/fault_filter_test.cc b/test/common/http/filter/fault_filter_test.cc index 053165bf2967..9d568f582eb7 100644 --- a/test/common/http/filter/fault_filter_test.cc +++ b/test/common/http/filter/fault_filter_test.cc @@ -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) + .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)); + EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_headers_)); + + filter_callbacks_.reset_callback_(); +} + } // Http From 949904e2d012d9620ee15ad476a7887cc81965ef Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Mon, 16 Jan 2017 18:12:30 -0500 Subject: [PATCH 2/2] remove Times(1) and useless decodeTrailers test --- test/common/http/filter/fault_filter_test.cc | 24 ++------------------ 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/test/common/http/filter/fault_filter_test.cc b/test/common/http/filter/fault_filter_test.cc index 9d568f582eb7..2cb418f19e02 100644 --- a/test/common/http/filter/fault_filter_test.cc +++ b/test/common/http/filter/fault_filter_test.cc @@ -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); @@ -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"}}; @@ -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); @@ -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"); @@ -279,7 +271,6 @@ 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 @@ -287,7 +278,7 @@ TEST_F(FaultFilterTest, FixedDelayNonZeroDuration) { 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)); @@ -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"); @@ -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"}}; @@ -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"); @@ -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"}}; @@ -418,11 +401,9 @@ TEST_F(FaultFilterTest, TimerResetAfterStreamReset) { // Prep up with a 5s delay 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("FixedDelayWithStreamReset"); @@ -430,7 +411,7 @@ TEST_F(FaultFilterTest, TimerResetAfterStreamReset) { EXPECT_CALL(*timer_, enableTimer(std::chrono::milliseconds(5000UL))); EXPECT_CALL(filter_callbacks_.request_info_, - setResponseFlag(Http::AccessLog::ResponseFlag::DelayInjected)).Times(1); + setResponseFlag(Http::AccessLog::ResponseFlag::DelayInjected)); EXPECT_EQ(0UL, config_->stats().delays_injected_.value()); @@ -450,7 +431,6 @@ TEST_F(FaultFilterTest, TimerResetAfterStreamReset) { EXPECT_EQ(0UL, config_->stats().aborts_injected_.value()); EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true)); - EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_headers_)); filter_callbacks_.reset_callback_(); }