From f945415210f0e18c2c6d941fda6b7d45cb0f06f1 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Wed, 13 Mar 2013 06:26:25 +0000 Subject: Large changes to the LLCurl::Responder API, as well as pulling in some changes to common libraries from the server codebase: * Additional error checking in http handlers. * Uniform log spam for http errors. * Switch to using constants for http heads and status codes. * Fixed bugs in incorrectly checking if parsing LLSD xml resulted in an error. * Reduced spam regarding LLSD parsing errors in the default completedRaw http handler. It should not longer be necessary to short-circuit completedRaw to avoid spam. * Ported over a few bug fixes from the server code. * Switch mode http status codes to use S32 instead of U32. * Ported LLSD::asStringRef from server code; avoids copying strings all over the place. * Ported server change to LLSD::asBinary; this always returns a reference now instead of copying the entire binary blob. * Ported server pretty notation format (and pretty binary format) to llsd serialization. * The new LLCurl::Responder API no longer has two error handlers to choose from. Overriding the following methods have been deprecated: ** error - use httpFailure ** errorWithContent - use httpFailure ** result - use httpSuccess ** completed - use httpCompleted ** completedHeader - no longer necessary; call getResponseHeaders() from a completion method to obtain these headers. * In order to 'catch' a completed http request, override one of these methods: ** httpSuccess - Called for any 2xx status code. ** httpFailure - Called for any non-2xx status code. ** httpComplete - Called for all status codes. Default implementation is to call either httpSuccess or httpFailure. * It is recommended to keep these methods protected/private in order to avoid triggering of these methods without using a 'push' method (see below). * Uniform error handling should followed whenever possible by calling a variant of this during httpFailure: ** llwarns << dumpResponse() << llendl; * Be sure to include LOG_CLASS(your_class_name) in your class in order for the log entry to give more context. * In order to 'push' a result into the responder, you should no longer call error, errorWithContent, result, or completed. * Nor should you directly call httpSuccess/Failure/Completed (unless passing a message up to a parent class). * Instead, you can set the internal content of a responder and trigger a corresponding method using the following methods: ** successResult - Sets results and calls httpSuccess ** failureResult - Sets results and calls httpFailure ** completedResult - Sets results and calls httpCompleted * To obtain information about a the response from a reponder method, use the following getters: ** getStatus - HTTP status code ** getReason - Reason string ** getContent - Content (Parsed body LLSD) ** getResponseHeaders - Response Headers (LLSD map) ** getHTTPMethod - HTTP method of the request ** getURL - URL of the request * It is still possible to override completeRaw if you want to manipulate data directly out of LLPumpIO. * See indra/llmessage/llcurl.h for more information. --- indra/test/llassetuploadqueue_tut.cpp | 4 +-- indra/test/llblowfish_tut.cpp | 2 +- indra/test/llhttpnode_tut.cpp | 1 + indra/test/llsd_new_tut.cpp | 55 ++++++++++------------------------- indra/test/llsdtraits.h | 2 +- indra/test/message_tut.cpp | 3 +- indra/test/mock_http_client.h | 23 +++++++-------- 7 files changed, 34 insertions(+), 56 deletions(-) (limited to 'indra/test') diff --git a/indra/test/llassetuploadqueue_tut.cpp b/indra/test/llassetuploadqueue_tut.cpp index ec952e0058..25efe63d3f 100644 --- a/indra/test/llassetuploadqueue_tut.cpp +++ b/indra/test/llassetuploadqueue_tut.cpp @@ -45,11 +45,11 @@ LLAssetUploadResponder::~LLAssetUploadResponder() { } -void LLAssetUploadResponder::error(U32 statusNum, const std::string& reason) +void LLAssetUploadResponder::httpFailure() { } -void LLAssetUploadResponder::result(const LLSD& content) +void LLAssetUploadResponder::httpSuccess() { } diff --git a/indra/test/llblowfish_tut.cpp b/indra/test/llblowfish_tut.cpp index 2573cab81f..20e7960829 100644 --- a/indra/test/llblowfish_tut.cpp +++ b/indra/test/llblowfish_tut.cpp @@ -65,7 +65,7 @@ namespace tut } if (!fp) { - llwarns << "unabled to open " << filename << llendl; + llwarns << "unable to open " << filename << llendl; return false; } diff --git a/indra/test/llhttpnode_tut.cpp b/indra/test/llhttpnode_tut.cpp index 216c59d766..d580263103 100644 --- a/indra/test/llhttpnode_tut.cpp +++ b/indra/test/llhttpnode_tut.cpp @@ -81,6 +81,7 @@ namespace tut void result(const LLSD& result) { mResult = result; } void status(S32 code, const std::string& message) { } void extendedResult(S32 code, const std::string& message, const LLSD& headers) { } + void extendedResult(S32 code, const LLSD& result, const LLSD& headers) { } private: Response() {;} // Must be accessed through LLPointer. diff --git a/indra/test/llsd_new_tut.cpp b/indra/test/llsd_new_tut.cpp index f928a1bad0..03df1d339b 100644 --- a/indra/test/llsd_new_tut.cpp +++ b/indra/test/llsd_new_tut.cpp @@ -93,6 +93,18 @@ namespace tut ensure( s + " type", traits.checkType(actual)); ensure_equals( s + " value", traits.get(actual), expectedValue); } + + template + static void ensureTypeAndRefValue(const char* msg, const LLSD& actual, + const T& expectedValue) + { + LLSDTraits traits; + + std::string s(msg); + + ensure( s + " type", traits.checkType(actual)); + ensure_equals( s + " value", traits.get(actual), expectedValue); + } }; typedef test_group SDTestGroup; @@ -162,7 +174,7 @@ namespace tut std::vector data; copy(&source[0], &source[sizeof(source)], back_inserter(data)); - v = data; ensureTypeAndValue("set to data", v, data); + v = data; ensureTypeAndRefValue("set to data", v, data); v.clear(); ensure("reset to undefined", v.type() == LLSD::TypeUndefined); @@ -213,8 +225,8 @@ namespace tut const char source[] = "once in a blue moon"; std::vector data; copy(&source[0], &source[sizeof(source)], back_inserter(data)); - LLSD x1(data); ensureTypeAndValue("construct vector", x1, data); - LLSD x2 = data; ensureTypeAndValue("initialize vector", x2, data); + LLSD x1(data); ensureTypeAndRefValue("construct vector", x1, data); + LLSD x2 = data; ensureTypeAndRefValue("initialize vector", x2, data); } void checkConversions(const char* msg, const LLSD& v, @@ -754,42 +766,6 @@ namespace tut w = "nice day"; } - { - SDAllocationCheck check("shared values test for threaded work", 9); - - //U32 start_llsd_count = llsd::outstandingCount(); - - LLSD m = LLSD::emptyMap(); - - m["one"] = 1; - m["two"] = 2; - m["one_copy"] = m["one"]; // 3 (m, "one" and "two") - - m["undef_one"] = LLSD(); - m["undef_two"] = LLSD(); - m["undef_one_copy"] = m["undef_one"]; - - { // Ensure first_array gets freed to avoid counting it - LLSD first_array = LLSD::emptyArray(); - first_array.append(1.0f); - first_array.append(2.0f); - first_array.append(3.0f); // 7 - - m["array"] = first_array; - m["array_clone"] = first_array; - m["array_copy"] = m["array"]; // 7 - } - - m["string_one"] = "string one value"; - m["string_two"] = "string two value"; - m["string_one_copy"] = m["string_one"]; // 9 - - //U32 llsd_object_count = llsd::outstandingCount(); - //std::cout << "Using " << (llsd_object_count - start_llsd_count) << " LLSD objects" << std::endl; - - //m.dumpStats(); - } - { SDAllocationCheck check("shared values test for threaded work", 9); @@ -852,3 +828,4 @@ namespace tut test serializations */ } + diff --git a/indra/test/llsdtraits.h b/indra/test/llsdtraits.h index 8144aaee94..07f6193ce2 100644 --- a/indra/test/llsdtraits.h +++ b/indra/test/llsdtraits.h @@ -93,7 +93,7 @@ LLSDTraits::LLSDTraits() { } template<> inline -LLSDTraits::LLSDTraits() +LLSDTraits::LLSDTraits() : type(LLSD::TypeBinary), getter(&LLSD::asBinary) { } diff --git a/indra/test/message_tut.cpp b/indra/test/message_tut.cpp index d971b33475..0dae5178be 100644 --- a/indra/test/message_tut.cpp +++ b/indra/test/message_tut.cpp @@ -46,6 +46,7 @@ namespace mStatus = code; } virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { } + virtual void extendedResult(S32 code, const LLSD& result, const LLSD& headers) { } S32 mStatus; }; } @@ -142,7 +143,7 @@ namespace tut const LLSD message; const LLPointer response = new Response(); gMessageSystem->dispatch(name, message, response); - ensure_equals(response->mStatus, 404); + ensure_equals(response->mStatus, HTTP_NOT_FOUND); } } diff --git a/indra/test/mock_http_client.h b/indra/test/mock_http_client.h index 7668a43fdf..a2b9b435fb 100644 --- a/indra/test/mock_http_client.h +++ b/indra/test/mock_http_client.h @@ -98,7 +98,7 @@ namespace tut if (mSawError) { std::string msg = - llformat("error() called when not expected, status %d", + llformat("httpFailure() called when not expected, status %d", mStatus); fail(msg); } @@ -108,7 +108,7 @@ namespace tut { if (!mSawError) { - fail("error() wasn't called"); + fail("httpFailure() wasn't called"); } } @@ -119,7 +119,7 @@ namespace tut protected: bool mSawError; - U32 mStatus; + S32 mStatus; std::string mReason; bool mSawCompleted; LLSD mResult; @@ -144,23 +144,22 @@ namespace tut mClient.mResultDeleted = true; } - virtual void error(U32 status, const std::string& reason) + protected: + virtual void httpFailure() { mClient.mSawError = true; - mClient.mStatus = status; - mClient.mReason = reason; + mClient.mStatus = getStatus(); + mClient.mReason = getReason(); } - virtual void result(const LLSD& content) + virtual void httpSuccess() { - mClient.mResult = content; + mClient.mResult = getContent(); } - virtual void completed( - U32 status, const std::string& reason, - const LLSD& content) + virtual void httpCompleted() { - LLHTTPClient::Responder::completed(status, reason, content); + LLHTTPClient::Responder::httpCompleted(); mClient.mSawCompleted = true; } -- cgit v1.2.3 From beeefb45269f45ea717f58b30a0985951ae23c20 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Thu, 4 Apr 2013 21:50:45 +0000 Subject: Renaming HTTP_HEADER_* into HTTP_IN_HEADER_* and HTTP_OUT_HEADER_* to make it more clear which header strings should be used for incoming vs outgoing situations. Using constants for commonly used llhttpnode context strings. --- indra/test/llhttpnode_tut.cpp | 2 +- indra/test/mock_http_client.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/test') diff --git a/indra/test/llhttpnode_tut.cpp b/indra/test/llhttpnode_tut.cpp index d580263103..c528a34129 100644 --- a/indra/test/llhttpnode_tut.cpp +++ b/indra/test/llhttpnode_tut.cpp @@ -44,7 +44,7 @@ namespace tut std::ostringstream pathOutput; bool addSlash = false; - LLSD& remainder = mContext["request"]["remainder"]; + LLSD& remainder = mContext[CONTEXT_REQUEST]["remainder"]; for (LLSD::array_const_iterator i = remainder.beginArray(); i != remainder.endArray(); ++i) diff --git a/indra/test/mock_http_client.cpp b/indra/test/mock_http_client.cpp index d7ef407d52..e72902bfc2 100644 --- a/indra/test/mock_http_client.cpp +++ b/indra/test/mock_http_client.cpp @@ -25,8 +25,7 @@ */ #include "linden_common.h" -#include "llsdhttpserver.h" -#include "lliohttpserver.h" +#include "llhttpnode.h" namespace tut { -- cgit v1.2.3 From e3bad9fb86c3f44ad67488402ce2e46743a2422e Mon Sep 17 00:00:00 2001 From: "Brad Payne (Vir Linden)" Date: Tue, 16 Apr 2013 20:27:49 -0400 Subject: SH-4061 WIP - fix for build issues on mac, reset the retry policy on success. --- indra/test/lltut.h | 10 ++++++++++ 1 file changed, 10 insertions(+) mode change 100644 => 100755 indra/test/lltut.h (limited to 'indra/test') diff --git a/indra/test/lltut.h b/indra/test/lltut.h old mode 100644 new mode 100755 index 55d84bcaca..243e869be7 --- a/indra/test/lltut.h +++ b/indra/test/lltut.h @@ -65,6 +65,16 @@ namespace tut ensure_approximately_equals(NULL, actual, expected, frac_bits); } + inline void ensure_approximately_equals_range(const char *msg, F32 actual, F32 expected, F32 delta) + { + if (fabs(actual-expected)>delta) + { + std::stringstream ss; + ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected << " tolerance: " << delta; + throw tut::failure(ss.str().c_str()); + } + } + inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len) { if((expected_len != actual_len) || -- cgit v1.2.3 From b30bfd37534b1000075c87ab681e5590b2c4a57a Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Mon, 10 Feb 2014 20:06:05 -0500 Subject: STORM-1915 Fix unit tests --- indra/test/llsdmessagebuilder_tut.cpp | 2 +- indra/test/lltemplatemessagebuilder_tut.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/test') diff --git a/indra/test/llsdmessagebuilder_tut.cpp b/indra/test/llsdmessagebuilder_tut.cpp index be0692557a..b7283f53a6 100644 --- a/indra/test/llsdmessagebuilder_tut.cpp +++ b/indra/test/llsdmessagebuilder_tut.cpp @@ -649,7 +649,7 @@ namespace tut template<> template<> void LLSDMessageBuilderTestObject::test<37>() { - LLQuaternion data(1,2,3,0); + LLQuaternion data(0.3713907f, 0.5570861f, 0.7427813f,0.0f); //we send a quaternion packed into a vec3 (w is infered) - so sizeof(vec) == 12 bytes not 16. LLVector3 vec = data.packToVector3(); diff --git a/indra/test/lltemplatemessagebuilder_tut.cpp b/indra/test/lltemplatemessagebuilder_tut.cpp index 6e1c82bb24..b4495a9d0b 100644 --- a/indra/test/lltemplatemessagebuilder_tut.cpp +++ b/indra/test/lltemplatemessagebuilder_tut.cpp @@ -320,7 +320,7 @@ namespace tut { LLMessageTemplate messageTemplate = defaultTemplate(); messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); - LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); + LLQuaternion outValue, inValue = LLQuaternion(0.3713907f, 0.5570861f, 0.7427813f,0.0f); LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); builder->addQuat(_PREHASH_Test0, inValue); LLTemplateMessageReader* reader = setReader(messageTemplate, builder); @@ -787,7 +787,7 @@ namespace tut { LLMessageTemplate messageTemplate = defaultTemplate(); messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); - LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); + LLQuaternion outValue, inValue = LLQuaternion(0.3713907f, 0.5570861f, 0.7427813f,0.0f); LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); builder->addQuat(_PREHASH_Test0, inValue); LLTemplateMessageReader* reader = setReader( -- cgit v1.2.3 From 34b2f2d1f841f7b7f93386d66be6943910cd055b Mon Sep 17 00:00:00 2001 From: Stinson Linden Date: Fri, 16 May 2014 22:44:25 +0100 Subject: MAINT-4009: First pass refactoring to eliminate memory related to error reporting that is not properly cleaned up. --- indra/test/test.cpp | 62 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'indra/test') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 10f71a2843..0dd21b6a05 100755 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -95,25 +95,20 @@ public: virtual void replay(std::ostream&) {} }; -class LLReplayLogReal: public LLReplayLog, public LLError::Recorder, public boost::noncopyable +class RecordToTempFile : public LLError::Recorder, public boost::noncopyable { public: - LLReplayLogReal(LLError::ELevel level, apr_pool_t* pool): - mOldSettings(LLError::saveAndResetSettings()), - mProxy(new RecorderProxy(this)), - mTempFile("log", "", pool), // create file - mFile(mTempFile.getName().c_str()) // open it + RecordToTempFile(apr_pool_t* pPool) + : LLError::Recorder(), + boost::noncopyable(), + mTempFile("log", "", pPool), + mFile(mTempFile.getName().c_str()) { - LLError::setFatalFunction(wouldHaveCrashed); - LLError::setDefaultLevel(level); - LLError::addRecorder(mProxy); } - virtual ~LLReplayLogReal() + virtual ~RecordToTempFile() { - LLError::removeRecorder(mProxy); - delete mProxy; - LLError::restoreSettings(mOldSettings); + mFile.close(); } virtual void recordMessage(LLError::ELevel level, const std::string& message) @@ -121,13 +116,13 @@ public: mFile << message << std::endl; } - virtual void reset() + void reset() { mFile.close(); mFile.open(mTempFile.getName().c_str()); } - virtual void replay(std::ostream& out) + void replay(std::ostream& out) { mFile.close(); std::ifstream inf(mTempFile.getName().c_str()); @@ -139,12 +134,45 @@ public: } private: - LLError::Settings* mOldSettings; - LLError::Recorder* mProxy; NamedTempFile mTempFile; std::ofstream mFile; }; +class LLReplayLogReal: public LLReplayLog, public boost::noncopyable +{ +public: + LLReplayLogReal(LLError::ELevel level, apr_pool_t* pool) + : LLReplayLog(), + boost::noncopyable(), + mOldSettings(LLError::saveAndResetSettings()), + mRecorder(new RecordToTempFile(pool)) + { + LLError::setFatalFunction(wouldHaveCrashed); + LLError::setDefaultLevel(level); + LLError::addRecorder(mRecorder); + } + + virtual ~LLReplayLogReal() + { + LLError::removeRecorder(mRecorder); + LLError::restoreSettings(mOldSettings); + } + + virtual void reset() + { + boost::dynamic_pointer_cast(mRecorder)->reset(); + } + + virtual void replay(std::ostream& out) + { + boost::dynamic_pointer_cast(mRecorder)->replay(out); + } + +private: + LLError::Settings* mOldSettings; + LLError::RecorderPtr mRecorder; +}; + class LLTestCallback : public tut::callback { public: -- cgit v1.2.3 From 08e83a341e76de8fa4d8c4a974edbe3e0bd1c128 Mon Sep 17 00:00:00 2001 From: Stinson Linden Date: Sat, 17 May 2014 00:41:36 +0100 Subject: MAINT-4009: Final pass refactoring to eliminate memory allocation related to error reporting that is not properly cleaned up. --- indra/test/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/test') diff --git a/indra/test/test.cpp b/indra/test/test.cpp index 0dd21b6a05..e42374d56b 100755 --- a/indra/test/test.cpp +++ b/indra/test/test.cpp @@ -169,7 +169,7 @@ public: } private: - LLError::Settings* mOldSettings; + LLError::SettingsStoragePtr mOldSettings; LLError::RecorderPtr mRecorder; }; -- cgit v1.2.3