diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-04-12 17:04:48 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-04-12 17:04:48 -0400 |
commit | bb237ce15f0a7bc4a3fbffc45b1e4548fd1d2f81 (patch) | |
tree | bba6ac1e44172c6f95f46802ec189a3fe47dcd44 /indra/newview | |
parent | a8cdcfc9a893b7debf7c006022b57c389b50bf0d (diff) |
SH_4061 WIP - retry policy org and tests
Diffstat (limited to 'indra/newview')
-rwxr-xr-x | indra/newview/llhttpretrypolicy.cpp | 23 | ||||
-rwxr-xr-x | indra/newview/llhttpretrypolicy.h | 11 | ||||
-rwxr-xr-x | indra/newview/tests/llhttpretrypolicy_test.cpp | 33 |
3 files changed, 50 insertions, 17 deletions
diff --git a/indra/newview/llhttpretrypolicy.cpp b/indra/newview/llhttpretrypolicy.cpp index 5c6dabbe99..82f6eab00e 100755 --- a/indra/newview/llhttpretrypolicy.cpp +++ b/indra/newview/llhttpretrypolicy.cpp @@ -28,6 +28,17 @@ #include "llhttpretrypolicy.h" +LLAdaptiveRetryPolicy::LLAdaptiveRetryPolicy(F32 min_delay, F32 max_delay, F32 backoff_factor, U32 max_retries): + mMinDelay(min_delay), + mMaxDelay(max_delay), + mBackoffFactor(backoff_factor), + mMaxRetries(max_retries), + mDelay(min_delay), + mRetryCount(0), + mShouldRetry(true) +{ +} + bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, F32& retry_header_time) { return (headers.has(HTTP_IN_HEADER_RETRY_AFTER) @@ -77,6 +88,11 @@ void LLAdaptiveRetryPolicy::onFailure(const LLCore::HttpResponse *response) void LLAdaptiveRetryPolicy::onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time) { + if (!mShouldRetry) + { + llinfos << "keep on failing" << llendl; + return; + } if (mRetryCount > 0) { mDelay = llclamp(mDelay*mBackoffFactor,mMinDelay,mMaxDelay); @@ -111,7 +127,12 @@ void LLAdaptiveRetryPolicy::onFailureCommon(S32 status, bool has_retry_header_ti bool LLAdaptiveRetryPolicy::shouldRetry(F32& seconds_to_wait) const { - llassert(mRetryCount>0); // have to call onFailure() before shouldRetry() + if (mRetryCount == 0) + { + // Called shouldRetry before any failure. + seconds_to_wait = F32_MAX; + return false; + } seconds_to_wait = mShouldRetry ? mRetryTimer.getRemainingTimeF32() : F32_MAX; return mShouldRetry; } diff --git a/indra/newview/llhttpretrypolicy.h b/indra/newview/llhttpretrypolicy.h index ca37e5f73c..6f63f047de 100755 --- a/indra/newview/llhttpretrypolicy.h +++ b/indra/newview/llhttpretrypolicy.h @@ -56,16 +56,7 @@ public: class LLAdaptiveRetryPolicy: public LLHTTPRetryPolicy { public: - LLAdaptiveRetryPolicy(F32 min_delay, F32 max_delay, F32 backoff_factor, U32 max_retries): - mMinDelay(min_delay), - mMaxDelay(max_delay), - mBackoffFactor(backoff_factor), - mMaxRetries(max_retries), - mDelay(min_delay), - mRetryCount(0), - mShouldRetry(true) - { - } + LLAdaptiveRetryPolicy(F32 min_delay, F32 max_delay, F32 backoff_factor, U32 max_retries); // virtual void onFailure(S32 status, const LLSD& headers); diff --git a/indra/newview/tests/llhttpretrypolicy_test.cpp b/indra/newview/tests/llhttpretrypolicy_test.cpp index 39bd15d62f..43fc1178cc 100755 --- a/indra/newview/tests/llhttpretrypolicy_test.cpp +++ b/indra/newview/tests/llhttpretrypolicy_test.cpp @@ -45,8 +45,12 @@ void RetryPolicyTestObject::test<1>() LLSD headers; F32 wait_seconds; + // No retry until we've finished a try. + ensure("never retry 0", !never_retry.shouldRetry(wait_seconds)); + + // 0 retries max. never_retry.onFailure(500,headers); - ensure("never retry", !never_retry.shouldRetry(wait_seconds)); + ensure("never retry 1", !never_retry.shouldRetry(wait_seconds)); } template<> template<> @@ -70,6 +74,9 @@ void RetryPolicyTestObject::test<3>() bool should_retry; U32 frac_bits = 6; + // No retry until we've finished a try. + ensure("basic_retry 0", !basic_retry.shouldRetry(wait_seconds)); + // Starting wait 1.0 basic_retry.onFailure(500,headers); should_retry = basic_retry.shouldRetry(wait_seconds); @@ -224,10 +231,13 @@ void RetryPolicyTestObject::test<7>() time_t nowseconds; time(&nowseconds); sd_headers[HTTP_IN_HEADER_RETRY_AFTER] = LLDate((F64)nowseconds).asRFC1123(); - LLAdaptiveRetryPolicy policy(17.0,644.0,3.0,10); + LLAdaptiveRetryPolicy policy(17.0,644.0,3.0,5); F32 seconds_to_wait; bool should_retry; + // No retry until we've finished a try. + ensure("header 0", !policy.shouldRetry(seconds_to_wait)); + // no retry header, use default. policy.onFailure(500,LLSD()); should_retry = policy.shouldRetry(seconds_to_wait); @@ -246,7 +256,7 @@ void RetryPolicyTestObject::test<7>() LLCore::HttpHeaders *headers = new LLCore::HttpHeaders(); response->setStatus(503); response->setHeaders(headers); - headers->mHeaders.push_back("retry-after: 600"); + headers->mHeaders.push_back(HTTP_IN_HEADER_RETRY_AFTER + ": 600"); policy.onFailure(response); should_retry = policy.shouldRetry(seconds_to_wait); ensure("header 3",should_retry); @@ -262,13 +272,24 @@ void RetryPolicyTestObject::test<7>() response->setHeaders(headers); LLSD sd_headers; time(&nowseconds); - headers->mHeaders.push_back("retry-after: " + LLDate((F64)nowseconds).asRFC1123()); + headers->mHeaders.push_back(HTTP_IN_HEADER_RETRY_AFTER + ": " + LLDate((F64)nowseconds).asRFC1123()); policy.onFailure(response); should_retry = policy.shouldRetry(seconds_to_wait); - ensure("header 3",should_retry); - ensure_approximately_equals("header 3", seconds_to_wait, 0.0F, 6); + ensure("header 4",should_retry); + ensure_approximately_equals("header 4", seconds_to_wait, 0.0F, 6); response->release(); } + + // Timeout should be clamped at max. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 5", should_retry); + ensure_approximately_equals("header 5", seconds_to_wait, 644.0F, 6); + + // No more retries. + policy.onFailure(500,LLSD()); + should_retry = policy.shouldRetry(seconds_to_wait); + ensure("header 6", !should_retry); } } |