diff options
| author | Graham Madarasz <graham@lindenlab.com> | 2013-04-30 19:50:05 -0700 | 
|---|---|---|
| committer | Graham Madarasz <graham@lindenlab.com> | 2013-04-30 19:50:05 -0700 | 
| commit | 806d09b1143894ad66cea2c228f467e8c39a8adf (patch) | |
| tree | 512bfa5d5a8fe92ac4616fd9169e1c458b0e8b87 /indra/llmessage/tests | |
| parent | b06ec66a5d11628905da256e084d0036f39ba529 (diff) | |
Merge 3.5.1 into Materials
Diffstat (limited to 'indra/llmessage/tests')
| -rw-r--r-- | indra/llmessage/tests/llhttpclient_test.cpp | 82 | ||||
| -rw-r--r-- | indra/llmessage/tests/test_llsdmessage_peer.py | 46 | 
2 files changed, 42 insertions, 86 deletions
| diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp index 7c3def6024..559001d079 100644 --- a/indra/llmessage/tests/llhttpclient_test.cpp +++ b/indra/llmessage/tests/llhttpclient_test.cpp @@ -47,37 +47,6 @@  namespace tut  { -	LLSD storage; - -	class LLSDStorageNode : public LLHTTPNode -	{ -	public: -		LLSD simpleGet() const					{ return storage; } -		LLSD simplePut(const LLSD& value) const	{ storage = value; return LLSD(); } -	}; - -	class ErrorNode : public LLHTTPNode -	{ -	public: -		void get(ResponsePtr r, const LLSD& context) const -			{ r->status(599, "Intentional error"); } -		void post(ResponsePtr r, const LLSD& context, const LLSD& input) const -			{ r->status(input["status"], input["reason"]); } -	}; - -	class TimeOutNode : public LLHTTPNode -	{ -	public: -		void get(ResponsePtr r, const LLSD& context) const -		{ -            /* do nothing, the request will eventually time out */  -		} -	}; - -	LLHTTPRegistration<LLSDStorageNode> gStorageNode("/test/storage"); -	LLHTTPRegistration<ErrorNode>		gErrorNode("/test/error"); -	LLHTTPRegistration<TimeOutNode>		gTimeOutNode("/test/timeout"); -  	struct HTTPClientTestData  	{  	public: @@ -91,7 +60,6 @@ namespace tut  			ensure("Set environment variable PORT to local test server port", PORT);  			apr_pool_create(&mPool, NULL);  			LLCurl::initClass(false); -			mServerPump = new LLPumpIO(mPool);  			mClientPump = new LLPumpIO(mPool);  			LLHTTPClient::setPump(*mClientPump); @@ -99,20 +67,11 @@ namespace tut  		~HTTPClientTestData()  		{ -			delete mServerPump;  			delete mClientPump;  			LLProxy::cleanupClass();  			apr_pool_destroy(mPool);  		} -		void setupTheServer() -		{ -			LLHTTPNode& root = LLIOHTTPServer::create(mPool, *mServerPump, 8888); - -			LLHTTPStandardServices::useServices(); -			LLHTTPRegistrar::buildAllServices(root); -		} -  		void runThePump(float timeout = 100.0f)  		{  			LLTimer timer; @@ -120,11 +79,7 @@ namespace tut  			while(!mSawCompleted && !mSawCompletedHeader && !timer.hasExpired())  			{ -				if (mServerPump) -				{ -					mServerPump->pump(); -					mServerPump->callback(); -				} +				LLFrameTimer::updateFrameTime();  				if (mClientPump)  				{  					mClientPump->pump(); @@ -133,18 +88,11 @@ namespace tut  			}  		} -		void killServer() -		{ -			delete mServerPump; -			mServerPump = NULL; -		} -  		const char* const PORT;  		const std::string local_server;  	private:  		apr_pool_t* mPool; -		LLPumpIO* mServerPump;  		LLPumpIO* mClientPump;  	protected: @@ -288,9 +236,7 @@ namespace tut  		sd["list"][1]["three"] = 3;  		sd["list"][1]["four"] = 4; -		setupTheServer(); - -		LLHTTPClient::post("http://localhost:8888/web/echo", sd, newResult()); +		LLHTTPClient::post(local_server + "web/echo", sd, newResult());  		runThePump();  		ensureStatusOK();  		ensure_equals("echoed result matches", getResult(), sd); @@ -303,12 +249,11 @@ namespace tut  		sd["message"] = "This is my test message."; -		setupTheServer(); -		LLHTTPClient::put("http://localhost:8888/test/storage", sd, newResult()); +		LLHTTPClient::put(local_server + "test/storage", sd, newResult());  		runThePump();  		ensureStatusOK(); -		LLHTTPClient::get("http://localhost:8888/test/storage", newResult()); +		LLHTTPClient::get(local_server + "test/storage", newResult());  		runThePump();  		ensureStatusOK();  		ensure_equals("echoed result matches", getResult(), sd); @@ -322,9 +267,7 @@ namespace tut  		sd["status"] = 543;  		sd["reason"] = "error for testing"; -		setupTheServer(); - -		LLHTTPClient::post("http://localhost:8888/test/error", sd, newResult()); +		LLHTTPClient::post(local_server + "test/error", sd, newResult());  		runThePump();  		ensureStatusError();  		ensure_contains("reason", mReason, sd["reason"]); @@ -333,23 +276,16 @@ namespace tut  	template<> template<>  		void HTTPClientTestObject::test<6>()  	{ -		setupTheServer(); - -		LLHTTPClient::get("http://localhost:8888/test/timeout", newResult()); -		runThePump(1.0f); -		killServer(); -		runThePump(); +		const F32 timeout = 1.0f; +		LLHTTPClient::get(local_server + "test/timeout", newResult(), LLSD(), timeout); +		runThePump(timeout * 5.0f);  		ensureStatusError(); -		ensure_equals("reason", mReason, "STATUS_ERROR"); +		ensure_equals("reason", mReason, "STATUS_EXPIRED");  	}  	template<> template<>  		void HTTPClientTestObject::test<7>()  	{ -		// Can not use the little mini server.  The blocking request -		// won't ever let it run.  Instead get from a known LLSD -		// source and compare results with the non-blocking get which -		// is tested against the mini server earlier.  		LLHTTPClient::get(local_server, newResult());  		runThePump();  		ensureStatusOK(); diff --git a/indra/llmessage/tests/test_llsdmessage_peer.py b/indra/llmessage/tests/test_llsdmessage_peer.py index fe4f3a8c01..e45249b1cb 100644 --- a/indra/llmessage/tests/test_llsdmessage_peer.py +++ b/indra/llmessage/tests/test_llsdmessage_peer.py @@ -39,6 +39,9 @@ sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python"))  from indra.util.fastest_elementtree import parse as xml_parse  from indra.base import llsd  from testrunner import freeport, run, debug, VERBOSE +import time + +_storage=None  class TestHTTPRequestHandler(BaseHTTPRequestHandler):      """This subclass of BaseHTTPRequestHandler is to receive and echo @@ -90,21 +93,14 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):          # Read the provided POST data.          self.answer(self.read_xml()) +    def do_PUT(self): +        # Read the provided PUT data. +        self.answer(self.read_xml()) +      def answer(self, data, withdata=True): +        global _storage          debug("%s.answer(%s): self.path = %r", self.__class__.__name__, data, self.path) -        if "fail" not in self.path: -            data = data.copy()          # we're going to modify -            # Ensure there's a "reply" key in data, even if there wasn't before -            data["reply"] = data.get("reply", llsd.LLSD("success")) -            response = llsd.format_xml(data) -            debug("success: %s", response) -            self.send_response(200) -            self.send_header("Content-type", "application/llsd+xml") -            self.send_header("Content-Length", str(len(response))) -            self.end_headers() -            if withdata: -                self.wfile.write(response) -        else:                           # fail requested +        if "fail" in self.path or "test/error" in self.path: # fail requested              status = data.get("status", 500)              # self.responses maps an int status to a (short, long) pair of              # strings. We want the longer string. That's why we pass a string @@ -117,6 +113,30 @@ class TestHTTPRequestHandler(BaseHTTPRequestHandler):                                                     "without providing a reason" % status))[1])              debug("fail requested: %s: %r", status, reason)              self.send_error(status, reason) +        else: +            if "web/echo" in self.path: +                pass +            elif "test/timeout" in self.path: +                time.sleep(5.0) +                return +            elif "test/storage" in self.path: +                if "GET" == self.command: +                    data = _storage +                else: +                    _storage = data +                    data = "ok" +            else: +                data = data.copy()          # we're going to modify +                # Ensure there's a "reply" key in data, even if there wasn't before +                data["reply"] = data.get("reply", llsd.LLSD("success")) +            response = llsd.format_xml(data) +            debug("success: %s", response) +            self.send_response(200) +            self.send_header("Content-type", "application/llsd+xml") +            self.send_header("Content-Length", str(len(response))) +            self.end_headers() +            if withdata: +                self.wfile.write(response)      if not VERBOSE:          # When VERBOSE is set, skip both these overrides because they exist to | 
