summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/tests
diff options
context:
space:
mode:
authorMonty Brandenberg <monty@lindenlab.com>2012-06-26 12:28:58 -0400
committerMonty Brandenberg <monty@lindenlab.com>2012-06-26 12:28:58 -0400
commite8b0088d1a0c02bfa1f9768dc91fc3df4322adae (patch)
tree336f5484cf97d0538599250c4c405ac28866234c /indra/llcorehttp/tests
parente172ec84fa217aae8d1e51c1e0673322c30891fe (diff)
SH-3184/SH-3221 More work on cleanup with better unit test work and more aggressive shutdown of a thread.
Some additional work let me enable a memory check for the clean shutdown case and generally do a better job on other interfaces. Request queue waiters now awake on shutdown and don't sleep once the queue is turned off. Much better semantically for how this will be used.
Diffstat (limited to 'indra/llcorehttp/tests')
-rw-r--r--indra/llcorehttp/tests/test_httprequest.hpp309
1 files changed, 156 insertions, 153 deletions
diff --git a/indra/llcorehttp/tests/test_httprequest.hpp b/indra/llcorehttp/tests/test_httprequest.hpp
index ed049aa09c..ed4e239fe7 100644
--- a/indra/llcorehttp/tests/test_httprequest.hpp
+++ b/indra/llcorehttp/tests/test_httprequest.hpp
@@ -418,6 +418,156 @@ template <> template <>
void HttpRequestTestObjectType::test<5>()
{
ScopedCurlInit ready;
+
+ set_test_name("HttpRequest Spin (soft) + NoOp + hard termination");
+
+ // Handler can be stack-allocated *if* there are no dangling
+ // references to it after completion of this method.
+ // Create before memory record as the string copy will bump numbers.
+ TestHandler2 handler(this, "handler");
+
+ // record the total amount of dynamically allocated memory
+ mMemTotal = GetMemTotal();
+ mHandlerCalls = 0;
+
+ HttpRequest * req = NULL;
+
+ try
+ {
+
+ // Get singletons created
+ HttpRequest::createService();
+
+ // Start threading early so that thread memory is invariant
+ // over the test.
+ HttpRequest::startThread();
+
+ // create a new ref counted object with an implicit reference
+ req = new HttpRequest();
+ ensure("Memory allocated on construction", mMemTotal < GetMemTotal());
+
+ // Issue a Spin
+ HttpHandle handle = req->requestSpin(1);
+ ensure("Valid handle returned for spin request", handle != LLCORE_HTTP_HANDLE_INVALID);
+
+ // Issue a NoOp
+ handle = req->requestNoOp(&handler);
+ ensure("Valid handle returned for no-op request", handle != LLCORE_HTTP_HANDLE_INVALID);
+
+ // Run the notification pump.
+ int count(0);
+ int limit(10);
+ while (count++ < limit && mHandlerCalls < 1)
+ {
+ req->update(1000);
+ usleep(100000);
+ }
+ ensure("NoOp notification received", mHandlerCalls == 1);
+
+ // release the request object
+ delete req;
+ req = NULL;
+
+ // Shut down service
+ HttpRequest::destroyService();
+
+ // Check memory usage
+ // printf("Old mem: %d, New mem: %d\n", mMemTotal, GetMemTotal());
+ ensure("Memory usage back to that at entry", mMemTotal == GetMemTotal());
+ // This memory test should work but could give problems as it
+ // relies on the worker thread picking up a friendly request
+ // to shutdown. Doing so, it drops references to things and
+ // we should go back to where we started. If it gives you
+ // problems, look into the code before commenting things out.
+ }
+ catch (...)
+ {
+ stop_thread(req);
+ delete req;
+ HttpRequest::destroyService();
+ throw;
+ }
+}
+
+
+template <> template <>
+void HttpRequestTestObjectType::test<6>()
+{
+ ScopedCurlInit ready;
+
+ set_test_name("HttpRequest Spin + NoOp + hard termination");
+
+ // Handler can be stack-allocated *if* there are no dangling
+ // references to it after completion of this method.
+ // Create before memory record as the string copy will bump numbers.
+ TestHandler2 handler(this, "handler");
+
+ // record the total amount of dynamically allocated memory
+ mMemTotal = GetMemTotal();
+ mHandlerCalls = 0;
+
+ HttpRequest * req = NULL;
+
+ try
+ {
+
+ // Get singletons created
+ HttpRequest::createService();
+
+ // Start threading early so that thread memory is invariant
+ // over the test.
+ HttpRequest::startThread();
+
+ // create a new ref counted object with an implicit reference
+ req = new HttpRequest();
+ ensure("Memory allocated on construction", mMemTotal < GetMemTotal());
+
+ // Issue a Spin
+ HttpHandle handle = req->requestSpin(0); // Hard spin
+ ensure("Valid handle returned for spin request", handle != LLCORE_HTTP_HANDLE_INVALID);
+
+ // Issue a NoOp
+ handle = req->requestNoOp(&handler);
+ ensure("Valid handle returned for no-op request", handle != LLCORE_HTTP_HANDLE_INVALID);
+
+ // Run the notification pump.
+ int count(0);
+ int limit(10);
+ while (count++ < limit && mHandlerCalls < 1)
+ {
+ req->update(1000);
+ usleep(100000);
+ }
+ ensure("No notifications received", mHandlerCalls == 0);
+
+ // release the request object
+ delete req;
+ req = NULL;
+
+ // Shut down service
+ HttpRequest::destroyService();
+
+ // Check memory usage
+ // printf("Old mem: %d, New mem: %d\n", mMemTotal, GetMemTotal());
+ // ensure("Memory usage back to that at entry", mMemTotal == GetMemTotal());
+ // This memory test won't work because we're killing the thread
+ // hard with the hard spinner. There's no opportunity to join
+ // nicely so many things leak or get destroyed unilaterally.
+ }
+ catch (...)
+ {
+ stop_thread(req);
+ delete req;
+ HttpRequest::destroyService();
+ throw;
+ }
+}
+
+
+template <> template <>
+void HttpRequestTestObjectType::test<7>()
+{
+ ScopedCurlInit ready;
set_test_name("HttpRequest GET to dead port + Stop execution");
@@ -535,7 +685,7 @@ void HttpRequestTestObjectType::test<5>()
template <> template <>
-void HttpRequestTestObjectType::test<6>()
+void HttpRequestTestObjectType::test<8>()
{
ScopedCurlInit ready;
@@ -643,7 +793,7 @@ void HttpRequestTestObjectType::test<6>()
template <> template <>
-void HttpRequestTestObjectType::test<7>()
+void HttpRequestTestObjectType::test<9>()
{
ScopedCurlInit ready;
@@ -753,7 +903,7 @@ void HttpRequestTestObjectType::test<7>()
template <> template <>
-void HttpRequestTestObjectType::test<8>()
+void HttpRequestTestObjectType::test<10>()
{
ScopedCurlInit ready;
@@ -872,7 +1022,7 @@ void HttpRequestTestObjectType::test<8>()
}
template <> template <>
-void HttpRequestTestObjectType::test<9>()
+void HttpRequestTestObjectType::test<11>()
{
ScopedCurlInit ready;
@@ -991,7 +1141,7 @@ void HttpRequestTestObjectType::test<9>()
}
template <> template <>
-void HttpRequestTestObjectType::test<10>()
+void HttpRequestTestObjectType::test<12>()
{
ScopedCurlInit ready;
@@ -1104,7 +1254,7 @@ void HttpRequestTestObjectType::test<10>()
template <> template <>
-void HttpRequestTestObjectType::test<11>()
+void HttpRequestTestObjectType::test<13>()
{
ScopedCurlInit ready;
@@ -1230,153 +1380,6 @@ void HttpRequestTestObjectType::test<11>()
}
}
-template <> template <>
-void HttpRequestTestObjectType::test<12>()
-{
- ScopedCurlInit ready;
-
- set_test_name("HttpRequest Spin + NoOp + hard termination");
-
- // Handler can be stack-allocated *if* there are no dangling
- // references to it after completion of this method.
- // Create before memory record as the string copy will bump numbers.
- TestHandler2 handler(this, "handler");
-
- // record the total amount of dynamically allocated memory
- mMemTotal = GetMemTotal();
- mHandlerCalls = 0;
-
- HttpRequest * req = NULL;
-
- try
- {
-
- // Get singletons created
- HttpRequest::createService();
-
- // Start threading early so that thread memory is invariant
- // over the test.
- HttpRequest::startThread();
-
- // create a new ref counted object with an implicit reference
- req = new HttpRequest();
- ensure("Memory allocated on construction", mMemTotal < GetMemTotal());
-
- // Issue a Spin
- HttpHandle handle = req->requestSpin(0); // Hard spin
- ensure("Valid handle returned for spin request", handle != LLCORE_HTTP_HANDLE_INVALID);
-
- // Issue a NoOp
- handle = req->requestNoOp(&handler);
- ensure("Valid handle returned for no-op request", handle != LLCORE_HTTP_HANDLE_INVALID);
-
- // Run the notification pump.
- int count(0);
- int limit(10);
- while (count++ < limit && mHandlerCalls < 1)
- {
- req->update(1000);
- usleep(100000);
- }
- ensure("No notifications received", mHandlerCalls == 0);
-
- // release the request object
- delete req;
- req = NULL;
-
- // Shut down service
- HttpRequest::destroyService();
-
- // Check memory usage
- // printf("Old mem: %d, New mem: %d\n", mMemTotal, GetMemTotal());
- // ensure("Memory usage back to that at entry", mMemTotal == GetMemTotal());
- // This memory test won't work because we're killing the thread
- // hard with the hard spinner. There's no opportunity to join
- // nicely so many things leak or get destroyed unilaterally.
- }
- catch (...)
- {
- stop_thread(req);
- delete req;
- HttpRequest::destroyService();
- throw;
- }
-}
-
-template <> template <>
-void HttpRequestTestObjectType::test<13>()
-{
- ScopedCurlInit ready;
-
- set_test_name("HttpRequest Spin (soft) + NoOp + hard termination");
-
- // Handler can be stack-allocated *if* there are no dangling
- // references to it after completion of this method.
- // Create before memory record as the string copy will bump numbers.
- TestHandler2 handler(this, "handler");
-
- // record the total amount of dynamically allocated memory
- mMemTotal = GetMemTotal();
- mHandlerCalls = 0;
-
- HttpRequest * req = NULL;
-
- try
- {
-
- // Get singletons created
- HttpRequest::createService();
-
- // Start threading early so that thread memory is invariant
- // over the test.
- HttpRequest::startThread();
-
- // create a new ref counted object with an implicit reference
- req = new HttpRequest();
- ensure("Memory allocated on construction", mMemTotal < GetMemTotal());
-
- // Issue a Spin
- HttpHandle handle = req->requestSpin(1);
- ensure("Valid handle returned for spin request", handle != LLCORE_HTTP_HANDLE_INVALID);
-
- // Issue a NoOp
- handle = req->requestNoOp(&handler);
- ensure("Valid handle returned for no-op request", handle != LLCORE_HTTP_HANDLE_INVALID);
-
- // Run the notification pump.
- int count(0);
- int limit(10);
- while (count++ < limit && mHandlerCalls < 1)
- {
- req->update(1000);
- usleep(100000);
- }
- ensure("NoOp notification received", mHandlerCalls == 1);
-
- // release the request object
- delete req;
- req = NULL;
-
- // Shut down service
- HttpRequest::destroyService();
-
- // Check memory usage
- // printf("Old mem: %d, New mem: %d\n", mMemTotal, GetMemTotal());
- ensure("Memory usage back to that at entry", mMemTotal == GetMemTotal());
- // This memory test should work but could give problems as it
- // relies on the worker thread picking up a friendly request
- // to shutdown. Doing so, it drops references to things and
- // we should go back to where we started. If it gives you
- // problems, look into the code before commenting things out.
- }
- catch (...)
- {
- stop_thread(req);
- delete req;
- HttpRequest::destroyService();
- throw;
- }
-}
// *NB: This test must be last. The sleeping webserver
// won't respond for a long time.