Verify that servers have started up by reading their pid file.
authorBrian Aker <brian@gaz>
Fri, 16 Jul 2010 19:24:58 +0000 (12:24 -0700)
committerBrian Aker <brian@gaz>
Fri, 16 Jul 2010 19:24:58 +0000 (12:24 -0700)
tests/server.c

index 58a9d2764ba6a7757fa1395e7e3abd59b45e0ffe..c0521e5bb26d5dabc1d615d82048b2c8fb8bd1ec 100644 (file)
@@ -26,6 +26,8 @@
 #include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
 #include <unistd.h>
+#include <time.h>
+
 #include "server.h"
 
 void server_startup(server_startup_st *construct)
@@ -93,6 +95,39 @@ void server_startup(server_startup_st *construct)
       }
       *end_ptr= 0;
 
+      for (uint32_t x= 0; x < construct->count; x++)
+      {
+        uint32_t counter= 3;
+        char buffer[1024]; /* Nothing special for number */
+
+        snprintf(buffer, sizeof(buffer), "/tmp/%umemc.pid", x);
+
+        while (--counter)
+        {
+          int memcached_pid;
+
+          FILE *file;
+          file= fopen(buffer, "r");
+          if (file == NULL)
+          {
+            struct timespec req= { .tv_sec= 0, .tv_nsec= 5000 };
+            nanosleep(&req, NULL);
+
+            continue;
+          }
+          char *found= fgets(buffer, sizeof(buffer), file);
+          if (!found)
+          {
+            abort();
+          }
+          // Yes, we currently pitch this and don't make use of it.
+          memcached_pid= atoi(buffer);
+          fclose(file);
+        }
+
+
+      }
+
       construct->server_list= strdup(server_string_buffer);
     }
     printf("servers %s\n", construct->server_list);