Browse Source

Cleanup tests, and revert an error from a bad commit

Brian Aker 12 years ago
parent
commit
09ea1164bf
7 changed files with 84 additions and 43 deletions
  1. 1 4
      libgearman/connection.cc
  2. 1 1
      libtest/collection.cc
  3. 5 1
      libtest/dns.cc
  4. 2 2
      libtest/fatal.cc
  5. 0 2
      libtest/gearmand.cc
  6. 24 15
      libtest/server.cc
  7. 51 18
      tests/cycle.cc

+ 1 - 4
libgearman/connection.cc

@@ -560,10 +560,9 @@ size_t gearman_connection_st::send_and_flush(const void *data, size_t data_size,
 
 gearman_return_t gearman_connection_st::lookup()
 {
-  struct addrinfo *addrinfo= NULL;
-  struct addrinfo *addrinfo_next= NULL;
   if (addrinfo)
   {
+    freeaddrinfo(addrinfo);
     addrinfo= NULL;
   }
 
@@ -584,8 +583,6 @@ gearman_return_t gearman_connection_st::lookup()
   addrinfo_next= addrinfo;
   state= GEARMAN_CON_UNIVERSAL_CONNECT;
 
-  freeaddrinfo(addrinfo);
-
   return GEARMAN_SUCCESS;
 }
 

+ 1 - 1
libtest/collection.cc

@@ -121,7 +121,7 @@ test_return_t Collection::exec()
       catch (libtest::fatal &e)
       {
         Error << "Fatal exception was thrown: " << e.what();
-        stream::cerr(__FILE__, __LINE__, __func__) << e.what();
+        stream::cerr(e.file(), e.line(), e.func()) << e.what();
         _failed++;
         throw;
       }

+ 5 - 1
libtest/dns.cc

@@ -45,6 +45,7 @@ namespace libtest {
 
 bool lookup(const char* host)
 {
+  assert(host);
   bool success= false;
   struct addrinfo *addrinfo= NULL;
 
@@ -56,11 +57,14 @@ bool lookup(const char* host)
     {
       switch (ret)
       {
+      case EAI_NONAME:
+        break;
+
       case EAI_AGAIN:
         continue;
 
       default:
-        throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "getaddrinfo:%s", gai_strerror(ret));
+        throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "host: %s getaddrinfo:%s", host, gai_strerror(ret));
       }
     }
     else

+ 2 - 2
libtest/fatal.cc

@@ -54,7 +54,7 @@ fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const cha
 
     strncpy(_mesg, last_error, sizeof(_mesg));
 
-    snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
+    snprintf(_error_message, sizeof(_error_message), "%s", last_error);
   }
 
 static bool _disabled= false;
@@ -101,7 +101,7 @@ disconnected::disconnected(const char *file_arg, int line_arg, const char *func_
   (void)vsnprintf(last_error, sizeof(last_error), format, args);
   va_end(args);
 
-  snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
+  snprintf(_error_message, sizeof(_error_message), "%s", last_error);
 }
 
 } // namespace libtest

+ 0 - 2
libtest/gearmand.cc

@@ -94,9 +94,7 @@ public:
         gearman_client_free(client);
         return true;
       }
-#if 0
       Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client);
-#endif
     }
     else
     {

+ 24 - 15
libtest/server.cc

@@ -252,6 +252,7 @@ bool Server::start()
       }
 
       this_wait= retry * retry / 3 + 1;
+      Error << "dreaming" << this_wait;
       libtest::dream(this_wait, 0);
     }
   }
@@ -264,30 +265,38 @@ bool Server::start()
       _app.slurp();
       if (kill_file(pid_file()) == false)
       {
-        throw libtest::fatal(LIBYATL_DEFAULT_PARAM,
-                             "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s",
-                             this_wait,
-                             int(_running.size()), _running.c_str(),
-                             int(_app.stderr_result_length()), _app.stderr_c_str());
-      }
+        libtest::fatal err(LIBYATL_DEFAULT_PARAM,
+                           "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s",
+                           this_wait,
+                           int(_running.size()), _running.c_str(),
+                           int(_app.stderr_result_length()), _app.stderr_c_str());
 
-      throw libtest::fatal(LIBYATL_DEFAULT_PARAM, 
-                           "Failed native ping(), pid: %d is alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s",
+        stream::cerr(err.file(), err.line(), err.func()) << err.what();
+      }
+      else
+      {
+        libtest::fatal err(LIBYATL_DEFAULT_PARAM, 
+                           "Failed native ping(), pid: %d was alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s",
                            int(_app.pid()),
                            _app.check() ? "true" : "false",
                            this_wait,
                            int(_running.size()), _running.c_str(),
                            int(_app.stderr_result_length()), _app.stderr_c_str());
+
+        stream::cerr(err.file(), err.line(), err.func()) << err.what();
+      }
     }
     else
     {
-      throw libtest::fatal(LIBYATL_DEFAULT_PARAM,
-                           "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s",
-                           int(_app.pid()),
-                           _app.check() ? "true" : "false",
-                           this_wait,
-                           int(_running.size()), _running.c_str(),
-                           int(_app.stderr_result_length()), _app.stderr_c_str());
+      libtest::fatal err(LIBYATL_DEFAULT_PARAM,
+                         "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %.*s stderr:%.*s",
+                         int(_app.pid()),
+                         _app.check() ? "true" : "false",
+                         this_wait,
+                         int(_running.size()), _running.c_str(),
+                         int(_app.stderr_result_length()), _app.stderr_c_str());
+
+      stream::cerr(err.file(), err.line(), err.func()) << err.what();
     }
     _running.clear();
     return false;

+ 51 - 18
tests/cycle.cc

@@ -47,15 +47,36 @@ using namespace libtest;
 
 #include "tests/start_worker.h"
 
+struct cycle_context_st 
+{
+  cycle_context_st(libtest::server_startup_st& arg) :
+    servers(arg),
+    port(0)
+  {
+    reset();
+  }
+
+  void reset()
+  {
+    servers.clear();
+    port= get_free_port();
+  }
+
+  server_startup_st& servers;
+  in_port_t port;
+};
+
 static gearman_return_t success_fn(gearman_job_st*, void* /* context */)
 {
   return GEARMAN_SUCCESS;
 }
 
-static test_return_t single_cycle(void *)
+static test_return_t single_cycle(void* object)
 {
+  cycle_context_st *context= (cycle_context_st*)object;
+
   gearman_function_t success_function= gearman_function_create(success_fn);
-  worker_handle_st *worker= test_worker_start(libtest::default_port(), NULL, "success", success_function, NULL, gearman_worker_options_t());
+  worker_handle_st *worker= test_worker_start(context->port, NULL, "success", success_function, NULL, gearman_worker_options_t());
   test_true(worker);
   test_true(worker->shutdown());
   delete worker;
@@ -72,9 +93,9 @@ static test_return_t kill_test(void *)
 
 static test_return_t server_startup_single_TEST(void *obj)
 {
-  server_startup_st *servers= (server_startup_st*)obj;
-  test_compare(true, server_startup(*servers, "gearmand", libtest::get_free_port(), 0, NULL, false));
-  test_compare(true, servers->shutdown());
+  cycle_context_st *context= (cycle_context_st*)obj;
+  test_compare(true, server_startup(context->servers, "gearmand", context->port, 0, NULL, false));
+  test_compare(true, context->servers.shutdown());
 
 
   return TEST_SUCCESS;
@@ -82,20 +103,20 @@ static test_return_t server_startup_single_TEST(void *obj)
 
 static test_return_t server_startup_multiple_TEST(void *obj)
 {
-  server_startup_st *servers= (server_startup_st*)obj;
+  cycle_context_st *context= (cycle_context_st*)obj;
   for (size_t x= 0; x < 10; x++)
   {
-    test_compare(true, server_startup(*servers, "gearmand", libtest::get_free_port(), 0, NULL, false));
+    test_compare(true, server_startup(context->servers, "gearmand", context->port, 0, NULL, false));
   }
-  test_compare(true, servers->shutdown());
+  test_compare(true, context->servers.shutdown());
 
   return TEST_SUCCESS;
 }
 
 static test_return_t shutdown_and_remove_TEST(void *obj)
 {
-  server_startup_st *servers= (server_startup_st*)obj;
-  servers->clear();
+  cycle_context_st *context= (cycle_context_st*)obj;
+  context->servers.clear();
 
   return TEST_SUCCESS;
 }
@@ -120,26 +141,29 @@ test_st worker_tests[] ={
 
 static test_return_t collection_INIT(void *object)
 {
-  server_startup_st *servers= (server_startup_st*)object;
-  test_zero(servers->count());
-  test_compare(true, server_startup(*servers, "gearmand", libtest::default_port(), 0, NULL, false));
+  cycle_context_st *context= (cycle_context_st*)object;
+  test_zero(context->servers.count());
+  context->reset();
+
+  test_compare(true, server_startup(context->servers, "gearmand", context->port, 0, NULL, false));
 
   return TEST_SUCCESS;
 }
 
 static test_return_t validate_sanity_INIT(void *object)
 {
-  server_startup_st *servers= (server_startup_st*)object;
+  cycle_context_st *context= (cycle_context_st*)object;
 
-  test_zero(servers->count());
+  test_zero(context->servers.count());
+  context->reset();
 
   return TEST_SUCCESS;
 }
 
 static test_return_t collection_FINAL(void *object)
 {
-  server_startup_st *servers= (server_startup_st*)object;
-  servers->clear();
+  cycle_context_st *context= (cycle_context_st*)object;
+  context->reset();
 
   return TEST_SUCCESS;
 }
@@ -153,12 +177,21 @@ collection_st collection[] ={
 
 static void *world_create(server_startup_st& servers, test_return_t& )
 {
-  return &servers;
+  return new cycle_context_st(servers);
+}
+
+static bool world_destroy(void *object)
+{
+  cycle_context_st *context= (cycle_context_st*)object;
+  delete context;
+
+  return TEST_SUCCESS;
 }
 
 void get_world(Framework *world)
 {
   world->collections(collection);
   world->create(world_create);
+  world->destroy(world_destroy);
 }