Update for fix for testing if memcached is running.
[m6w6/libmemcached] / libtest / server.cc
index 726a01ba61f015637ae3d0f082892f0348491db5..a5d801a6fb00b4b4006973b07a309e8c3e26e2d9 100644 (file)
@@ -148,9 +148,14 @@ bool Server::cycle()
 
 bool Server::wait_for_pidfile() const
 {
-  Wait wait(pid_file(), 4);
+  if (has_pid_file())
+  {
+    Wait wait(pid_file(), 4);
+
+    return wait.successful();
+  }
 
-  return wait.successful();
+  return true;
 }
 
 bool Server::has_pid() const
@@ -164,7 +169,9 @@ bool Server::start()
   // If we find that we already have a pid then kill it.
   if (has_pid() == true)
   {
+#if 0
     fatal_message("has_pid() failed, programer error");
+#endif
   }
 
   // This needs more work.
@@ -190,6 +197,7 @@ bool Server::start()
     return false;
   }
 
+  libtest::release_port(_port);
   Application::error_t ret;
   if (Application::SUCCESS !=  (ret= _app.run()))
   {
@@ -203,29 +211,33 @@ bool Server::start()
     dream(5, 50000);
   }
 
-  size_t repeat= 5;
   _app.slurp();
-  while (--repeat)
+  if (has_pid_file())
   {
-    if (pid_file().empty() == false)
+    size_t repeat= 5;
+    while (--repeat)
     {
-      Wait wait(pid_file(), 8);
-
-      if (wait.successful() == false)
+      if (pid_file().empty() == false)
       {
-        if (_app.check())
+        Error << " here?";
+        Wait wait(pid_file(), 8);
+
+        if (wait.successful() == false)
         {
-          _app.slurp();
-          continue;
+          if (_app.check())
+          {
+            _app.slurp();
+            continue;
+          }
+
+          char buf[PATH_MAX];
+          char *getcwd_buf= getcwd(buf, sizeof(buf));
+          throw libtest::fatal(LIBYATL_DEFAULT_PARAM,
+                               "Unable to open pidfile in %s for: %s stderr:%s",
+                               getcwd_buf ? getcwd_buf : "",
+                               _running.c_str(),
+                               _app.stderr_c_str());
         }
-
-        char buf[PATH_MAX];
-        char *getcwd_buf= getcwd(buf, sizeof(buf));
-        throw libtest::fatal(LIBYATL_DEFAULT_PARAM,
-                             "Unable to open pidfile in %s for: %s stderr:%s",
-                             getcwd_buf ? getcwd_buf : "",
-                             _running.c_str(),
-                             _app.stderr_c_str());
       }
     }
   }
@@ -262,28 +274,29 @@ bool Server::start()
       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",
+                             "Failed to kill off server, waited: %u after startup occurred, when pinging failed: %.*s stderr:%.*s",
                              this_wait,
-                             pid_file().c_str(),
-                             _app.stderr_c_str());
+                             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",
+                           "Failed native ping(), pid: %d is alive: %s waited: %u server started, having pid_file. exec: %.*s stderr:%.*s",
                            int(_app.pid()),
                            _app.check() ? "true" : "false",
-                           this_wait, _running.c_str(), 
-                           _app.stderr_c_str());
+                           this_wait,
+                           int(_running.size()), _running.c_str(),
+                           int(_app.stderr_result_length()), _app.stderr_c_str());
     }
     else
     {
       throw libtest::fatal(LIBYATL_DEFAULT_PARAM,
-                           "Failed native ping(), pid: %d is alive: %s waited: %u server started. exec: %s stderr:%s",
+                           "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,
-                           _running.c_str(),
-                           _app.stderr_c_str());
+                           int(_running.size()), _running.c_str(),
+                           int(_app.stderr_result_length()), _app.stderr_c_str());
     }
     _running.clear();
     return false;
@@ -402,6 +415,7 @@ bool Server::args(Application& app)
   }
 
   // Update pid_file
+  if (has_pid_file())
   {
     if (_pid_file.empty() and set_pid_file() == false)
     {