SH-4061 WIP - moved retry policy to newview so it can work with either llmessage or CoreHttp libraries. Updated tests.

meow-7.2.2
Brad Payne (Vir Linden) 2013-04-12 09:16:25 -04:00
parent e17920defb
commit a8cdcfc9a8
6 changed files with 104 additions and 10 deletions

View File

@ -67,7 +67,6 @@ set(llmessage_SOURCE_FILES
llpartdata.cpp
llproxy.cpp
llpumpio.cpp
llhttpretrypolicy.cpp
llsdappservices.cpp
llsdhttpserver.cpp
llsdmessage.cpp
@ -267,6 +266,5 @@ if (LL_TESTS)
LL_ADD_INTEGRATION_TEST(llhttpclientadapter "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llpartdata "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llxfer_file "" "${test_libs}")
LL_ADD_INTEGRATION_TEST(llhttpretrypolicy "" "${test_libs}")
endif (LL_TESTS)

5
indra/newview/CMakeLists.txt Normal file → Executable file
View File

@ -299,6 +299,7 @@ set(viewer_SOURCE_FILES
llgroupmgr.cpp
llhints.cpp
llhomelocationresponder.cpp
llhttpretrypolicy.cpp
llhudeffect.cpp
llhudeffectbeam.cpp
llhudeffectlookat.cpp
@ -877,6 +878,7 @@ set(viewer_HEADER_FILES
llgrouplist.h
llgroupmgr.h
llhints.h
llhttpretrypolicy.h
llhomelocationresponder.h
llhudeffect.h
llhudeffectbeam.h
@ -2152,6 +2154,7 @@ if (LL_TESTS)
set(test_libs
${LLMESSAGE_LIBRARIES}
${LLCOREHTTP_LIBRARIES}
${WINDOWS_LIBRARIES}
${LLVFS_LIBRARIES}
${LLMATH_LIBRARIES}
@ -2197,6 +2200,8 @@ if (LL_TESTS)
"${test_libs}"
)
LL_ADD_INTEGRATION_TEST(llhttpretrypolicy "llhttpretrypolicy.cpp" "${test_libs}")
#ADD_VIEWER_BUILD_TEST(llmemoryview viewer)
#ADD_VIEWER_BUILD_TEST(llagentaccess viewer)
#ADD_VIEWER_BUILD_TEST(lltextureinfo viewer)

View File

@ -24,21 +24,56 @@
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llviewerprecompiledheaders.h"
#include "llhttpretrypolicy.h"
bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, retry_header_time)
bool LLAdaptiveRetryPolicy::getRetryAfter(const LLSD& headers, F32& retry_header_time)
{
return (headers.has(HTTP_IN_HEADER_RETRY_AFTER)
&& getSecondsUntilRetryAfter(headers[HTTP_IN_HEADER_RETRY_AFTER].asStringRef(), retry_header_time));
}
bool LLAdaptiveRetryPolicy::getRetryAfter(const LLCore::HttpHeaders *headers, F32& retry_header_time)
{
// Look for matching header. Hopefully it's correct enough to let
// us extract the field we are looking for. Does not purport to be
// in any way a viable general HTTP header parser.
if (headers)
{
for (std::vector<std::string>::const_iterator it = headers->mHeaders.begin();
it != headers->mHeaders.end();
++it)
{
const std::string& str = *it;
const std::string match = HTTP_IN_HEADER_RETRY_AFTER + ":";
size_t pos = str.find(match);
if ((pos != std::string::npos) &&
(pos+match.length() <= str.length()))
{
retry_header_time = strtod(str.substr(pos+match.length()).c_str(), NULL);
return true;
}
}
}
return false;
}
void LLAdaptiveRetryPolicy::onFailure(S32 status, const LLSD& headers)
{
F32 retry_header_time;
bool has_retry_header_time = getRetryAfter(headers,retry_header_time);
onFailureCommon(status, has_retry_header_time, retry_header_time);
}
// TODO: replace this parsing junk once CoreHttp has its own header parsing capabilities.
void LLAdaptiveRetryPolicy::onFailure(const LLCore::HttpResponse *response)
{
F32 retry_header_time;
const LLCore::HttpHeaders *headers = response->getHeaders();
bool has_retry_header_time = getRetryAfter(headers,retry_header_time);
onFailureCommon(response->getStatus().mType, has_retry_header_time, retry_header_time);
}
void LLAdaptiveRetryPolicy::onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time)
{

View File

@ -46,7 +46,7 @@ public:
// Call once after an HTTP failure to update state.
virtual void onFailure(S32 status, const LLSD& headers) = 0;
virtual void onFailure(const HttpResponse *response, const HttpHeaders *headers) = 0;
virtual void onFailure(const LLCore::HttpResponse *response) = 0;
virtual bool shouldRetry(F32& seconds_to_wait) const = 0;
};
@ -70,12 +70,13 @@ public:
// virtual
void onFailure(S32 status, const LLSD& headers);
// virtual
void onFailure(const HttpResponse *response, const HttpHeaders *headers);
void onFailure(const LLCore::HttpResponse *response);
// virtual
bool shouldRetry(F32& seconds_to_wait) const;
protected:
bool getRetryAfter(const LLSD& headers, retry_header_time)
bool getRetryAfter(const LLSD& headers, F32& retry_header_time);
bool getRetryAfter(const LLCore::HttpHeaders *headers, F32& retry_header_time);
void onFailureCommon(S32 status, bool has_retry_header_time, F32 retry_header_time);
private:

View File

@ -397,7 +397,7 @@ private:
e_tex_source mOriginFetchSource;
// Retry logic
LLAdaptiveRetryPolicy mFetchRetryPolicy;
//LLAdaptiveRetryPolicy mFetchRetryPolicy;
public:
//debug use

View File

@ -24,8 +24,8 @@
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "llhttpretrypolicy.h"
#include "../llviewerprecompiledheaders.h"
#include "../llhttpretrypolicy.h"
#include "lltut.h"
namespace tut
@ -216,5 +216,60 @@ void RetryPolicyTestObject::test<6>()
ensure_approximately_equals("parse 3", seconds_to_wait, 0.0F, 6);
}
// Test retry-after field in both llmessage and CoreHttp headers.
template<> template<>
void RetryPolicyTestObject::test<7>()
{
LLSD sd_headers;
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);
F32 seconds_to_wait;
bool should_retry;
// no retry header, use default.
policy.onFailure(500,LLSD());
should_retry = policy.shouldRetry(seconds_to_wait);
ensure("header 1", should_retry);
ensure_approximately_equals("header 1", seconds_to_wait, 17.0F, 6);
// retry header should override, give delay of 0
policy.onFailure(503,sd_headers);
should_retry = policy.shouldRetry(seconds_to_wait);
ensure("header 2", should_retry);
ensure_approximately_equals("header 2", seconds_to_wait, 0.0F, 6);
// retry header in LLCore::HttpHeaders
{
LLCore::HttpResponse *response = new LLCore::HttpResponse();
LLCore::HttpHeaders *headers = new LLCore::HttpHeaders();
response->setStatus(503);
response->setHeaders(headers);
headers->mHeaders.push_back("retry-after: 600");
policy.onFailure(response);
should_retry = policy.shouldRetry(seconds_to_wait);
ensure("header 3",should_retry);
ensure_approximately_equals("header 3", seconds_to_wait, 600.0F, 6);
response->release();
}
// retry header in LLCore::HttpHeaders
{
LLCore::HttpResponse *response = new LLCore::HttpResponse();
LLCore::HttpHeaders *headers = new LLCore::HttpHeaders();
response->setStatus(503);
response->setHeaders(headers);
LLSD sd_headers;
time(&nowseconds);
headers->mHeaders.push_back("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);
response->release();
}
}
}