summaryrefslogtreecommitdiff
path: root/indra/llmessage/tests/llhttpclient_test.cpp
diff options
context:
space:
mode:
authorOz Linden <oz@lindenlab.com>2013-11-19 17:59:55 -0500
committerOz Linden <oz@lindenlab.com>2013-11-19 17:59:55 -0500
commit0031e9a97be1bf6e9fe773c23506494d09ce91ae (patch)
tree220f195c82174b7cc8e94dceb2553e59fe5837a5 /indra/llmessage/tests/llhttpclient_test.cpp
parentb7edc965bc77ab21e9a1e3f6b424299a50053529 (diff)
parentebc9bcbf69f7a519677a6522979a6bf6cbb04bb8 (diff)
merge up to 3.6.10-release; some of the storm-68 changes lost
Diffstat (limited to 'indra/llmessage/tests/llhttpclient_test.cpp')
-rwxr-xr-x[-rw-r--r--]indra/llmessage/tests/llhttpclient_test.cpp118
1 files changed, 30 insertions, 88 deletions
diff --git a/indra/llmessage/tests/llhttpclient_test.cpp b/indra/llmessage/tests/llhttpclient_test.cpp
index 843c3bcc4b..559001d079 100644..100755
--- a/indra/llmessage/tests/llhttpclient_test.cpp
+++ b/indra/llmessage/tests/llhttpclient_test.cpp
@@ -47,67 +47,31 @@
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:
HTTPClientTestData():
- local_server(STRINGIZE("http://127.0.0.1:" << getenv("PORT") << "/"))
+ PORT(getenv("PORT")),
+ // Turning NULL PORT into empty string doesn't make things work;
+ // that's just to keep this initializer from blowing up. We test
+ // PORT separately in the constructor body.
+ local_server(STRINGIZE("http://127.0.0.1:" << (PORT? PORT : "") << "/"))
{
+ 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);
}
-
+
~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;
@@ -115,11 +79,7 @@ namespace tut
while(!mSawCompleted && !mSawCompletedHeader && !timer.hasExpired())
{
- if (mServerPump)
- {
- mServerPump->pump();
- mServerPump->callback();
- }
+ LLFrameTimer::updateFrameTime();
if (mClientPump)
{
mClientPump->pump();
@@ -128,17 +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:
@@ -148,11 +102,11 @@ namespace tut
{
std::string msg =
llformat("error() called when not expected, status %d",
- mStatus);
+ mStatus);
fail(msg);
}
}
-
+
void ensureStatusError()
{
if (!mSawError)
@@ -160,7 +114,7 @@ namespace tut
fail("error() wasn't called");
}
}
-
+
LLSD getResult()
{
return mResult;
@@ -169,7 +123,7 @@ namespace tut
{
return mHeader;
}
-
+
protected:
bool mSawError;
U32 mStatus;
@@ -187,18 +141,18 @@ namespace tut
: mClient(client)
{
}
-
+
public:
- static boost::intrusive_ptr<Result> build(HTTPClientTestData& client)
+ static Result* build(HTTPClientTestData& client)
{
- return boost::intrusive_ptr<Result>(new Result(client));
+ return new Result(client);
}
-
+
~Result()
{
mClient.mResultDeleted = true;
}
-
+
virtual void error(U32 status, const std::string& reason)
{
mClient.mSawError = true;
@@ -216,7 +170,7 @@ namespace tut
const LLSD& content)
{
LLHTTPClient::Responder::completed(status, reason, content);
-
+
mClient.mSawCompleted = true;
}
@@ -244,12 +198,12 @@ namespace tut
mResult.clear();
mHeader.clear();
mResultDeleted = false;
-
+
return Result::build(*this);
}
};
-
-
+
+
typedef test_group<HTTPClientTestData> HTTPClientTestGroup;
typedef HTTPClientTestGroup::object HTTPClientTestObject;
HTTPClientTestGroup httpClientTestGroup("http_client");
@@ -282,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);
@@ -297,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);
@@ -316,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"]);
@@ -327,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();