Browse Source

Sync text.

Brian Aker 13 years ago
parent
commit
2b834be27a
6 changed files with 48 additions and 12 deletions
  1. 4 2
      libtest/cmdline.cc
  2. 14 8
      libtest/memcached.cc
  3. 1 1
      libtest/server.h
  4. 4 0
      libtest/signal.cc
  5. 0 1
      libtest/unittest.cc
  6. 25 0
      libtest/wait.h

+ 4 - 2
libtest/cmdline.cc

@@ -303,7 +303,7 @@ bool Application::slurp()
   }
 
   bool data_was_read= false;
-  if (fds[0].revents == POLLIN)
+  if (fds[0].revents & POLLIN)
   {
     ssize_t read_length;
     char buffer[1024]= { 0 };
@@ -334,8 +334,10 @@ bool Application::slurp()
     }
   }
 
-  if (fds[1].revents == POLLIN)
+  if (fds[1].revents & POLLIN)
   {
+    stderr_fd.nonblock();
+
     ssize_t read_length;
     char buffer[1024]= { 0 };
     while ((read_length= ::read(stderr_fd.fd()[0], buffer, sizeof(buffer))))

+ 14 - 8
libtest/memcached.cc

@@ -101,17 +101,21 @@ public:
     return _username;
   }
 
+  bool wait_for_pidfile() const
+  {
+    Wait wait(pid(), 4);
+
+    return wait.successful();
+  }
+
   pid_t get_pid(bool error_is_ok)
   {
     // Memcached is slow to start, so we need to do this
-    if (pid_file().empty() == false)
+    if (error_is_ok and
+        wait_for_pidfile() == false)
     {
-      if (error_is_ok and
-          wait_for_pidfile() == false)
-      {
-        Error << "Pidfile was not found:" << pid_file();
-        return -1;
-      }
+      Error << "Pidfile was not found:" << pid_file();
+      return -1;
     }
 
     pid_t local_pid;
@@ -140,15 +144,17 @@ public:
 
   bool ping()
   {
+#if 0
     // Memcached is slow to start, so we need to do this
     if (pid_file().empty() == false)
     {
       if (wait_for_pidfile() == false)
       {
-        Error << "Pidfile was not found:" << pid_file();
+        Error << "Pidfile was not found:" << pid_file() << " :" << running();
         return -1;
       }
     }
+#endif
 
     memcached_return_t rc;
     bool ret;

+ 1 - 1
libtest/server.h

@@ -204,7 +204,7 @@ public:
 
   bool has_pid() const;
 
-  bool wait_for_pidfile() const;
+  virtual bool wait_for_pidfile() const;
 
   bool check_pid(pid_t pid_arg) const
   {

+ 4 - 0
libtest/signal.cc

@@ -143,6 +143,10 @@ static void *sig_thread(void *arg)
       }
       break;
 
+    case 0:
+      Error << "Inside of gdb?";
+      break;
+
     default:
       Error << "Signal handling thread got unexpected signal " <<  strsignal(sig);
       break;

+ 0 - 1
libtest/unittest.cc

@@ -388,7 +388,6 @@ static test_return_t application_doesnotexist_BINARY(void *)
   const char *args[]= { "--fubar", 0 };
 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
   test_compare(Application::INVALID, true_app.run(args));
-  test_compare(Application::INVALID, true_app.wait(false));
 #else
   test_compare(Application::SUCCESS, true_app.run(args));
   test_compare(Application::INVALID, true_app.wait());

+ 25 - 0
libtest/wait.h

@@ -24,6 +24,7 @@
 
 #include <unistd.h>
 #include <string>
+#include <signal.h>
 
 #include <libtest/dream.h>
 
@@ -63,6 +64,30 @@ public:
     }
   }
 
+  Wait(const pid_t &_pid_arg, uint32_t timeout= 6) :
+    _successful(false)
+  {
+    uint32_t waited;
+    uint32_t this_wait;
+    uint32_t retry;
+
+    for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
+    {
+      if (kill(_pid_arg, 0) == 0)
+      {
+        _successful= true;
+        break;
+      }
+      else if (waited >= timeout)
+      {
+        break;
+      }
+
+      this_wait= retry * retry / 3 + 1;
+      libtest::dream(this_wait, 0);
+    }
+  }
+
   bool successful() const
   {
     return _successful;