Browse Source

Move tests over for API check, also fixed OSX setup issue

Brian Aker 13 years ago
parent
commit
6913ffc5f5

+ 5 - 0
.bzrignore

@@ -122,3 +122,8 @@ libgearman-1.0/version.h
 tests/ephemeral_test
 gearmand/hostile_gearmand
 tests/redis_test
+tests/libgearman-1.0/client_test
+tests/libgearman-1.0/internals_test
+tests/libgearman-1.0/worker_test
+libgearman-1.0/t/c_test
+libgearman-1.0/t/cc_test

+ 36 - 17
gearmand/gearmand.cc

@@ -87,11 +87,15 @@ struct gearmand_log_info_st
   std::string filename;
   int fd;
   bool opt_syslog;
+  bool opt_file;
+  bool init_success;
 
   gearmand_log_info_st(const std::string &filename_arg, bool syslog_arg) :
     filename(filename_arg),
     fd(-1),
-    opt_syslog(syslog_arg)
+    opt_syslog(syslog_arg),
+    opt_file(false),
+    init_success(false)
   {
     if (opt_syslog)
     {
@@ -103,37 +107,45 @@ struct gearmand_log_info_st
 
   void init()
   {
-    if (filename.empty())
+    if (filename.size())
     {
-      return;
-    }
-
-    fd= open(filename.c_str(), O_CREAT | O_WRONLY | O_APPEND, 0644);
-    if (fd == -1)
-    {
-      if (opt_syslog)
+      fd= open(filename.c_str(), O_CREAT | O_WRONLY | O_APPEND, 0644);
+      if (fd == -1)
       {
-        syslog(LOG_ERR, "Could not open log file for writing:%.*s", int(filename.size()), filename.c_str());
+        if (opt_syslog)
+        {
+          char buffer[1024];
+          getcwd(buffer, sizeof(buffer));
+          syslog(LOG_ERR, "Could not open log file \"%.*s\", from \"%s\", open failed with (%s)", 
+                 int(filename.size()), filename.c_str(), 
+                 buffer,
+                 strerror(errno));
+        }
+        error::perror("Could not open log file for writing.");
+
+        fd= STDERR_FILENO;
+        return;
       }
-      error::perror("Could not open log file for writing.");
 
-      fd= STDERR_FILENO;
+      opt_file= true;
     }
+
+    init_success= true;
   }
 
-  int file() const
+  bool initialized() const
   {
-    return fd;
+    return init_success;
   }
 
-  bool has_file() const
+  int file() const
   {
-    return fd != STDERR_FILENO;
+    return fd;
   }
 
   void write(gearmand_verbose_t verbose, const char *mesg)
   {
-    if (has_file())
+    if (opt_file)
     {
       char buffer[GEARMAN_MAX_ERROR_SIZE];
       int buffer_length= snprintf(buffer, GEARMAN_MAX_ERROR_SIZE, "%7s %s\n", gearmand_verbose_name(verbose), mesg);
@@ -335,6 +347,11 @@ int main(int argc, char *argv[])
 
   gearmand_log_info_st log_info(log_file, opt_syslog);
 
+  if (log_info.initialized() == false)
+  {
+    return EXIT_FAILURE;
+  }
+
   gearmand_st *_gearmand= gearmand_create(host.empty() ? NULL : host.c_str(),
                                           port.c_str(), threads, backlog,
                                           static_cast<uint8_t>(job_retries),
@@ -404,7 +421,9 @@ static bool _set_fdlimit(rlim_t fds)
 
   rl.rlim_cur= fds;
   if (rl.rlim_max < rl.rlim_cur)
+  {
     rl.rlim_max= rl.rlim_cur;
+  }
 
   if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
   {

+ 2 - 0
libgearman-1.0/include.am

@@ -2,6 +2,8 @@
 # Gearman server and library 
 # Copyright (C) 2011 Data Differential, http://datadifferential.com/
 
+include libgearman-1.0/t/include.am
+
 nobase_include_HEADERS+= \
 			 libgearman-1.0/actions.h \
 			 libgearman-1.0/aggregator.h \

+ 1 - 1
libgearman-1.0/limits.h

@@ -43,7 +43,7 @@
 #define GEARMAN_DEFAULT_SOCKET_SEND_SIZE 32768
 #define GEARMAN_DEFAULT_SOCKET_TIMEOUT 10
 #define GEARMAN_DEFAULT_CONNECT_TIMEOUT 4000
-#define GEARMAN_DEFAULT_TCP_HOST "127.0.0.1"
+#define GEARMAN_DEFAULT_TCP_HOST "localhost"
 #define GEARMAN_FUNCTION_MAX_SIZE 512
 #define GEARMAN_JOB_HANDLE_SIZE 64
 #define GEARMAN_MAXIMUM_INTEGER_DISPLAY_LENGTH 20

+ 53 - 0
libgearman-1.0/t/c_test.c

@@ -0,0 +1,53 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Test C interface
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/ All
+ *  rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdlib.h>
+#include <libgearman-1.0/gearman.h>
+
+int main(void)
+{
+  gearman_client_st *client= gearman_client_create(NULL);
+
+  if (client == NULL)
+  {
+    return EXIT_FAILURE;
+  }
+
+  gearman_client_free(client);
+
+  return EXIT_SUCCESS;
+}

+ 54 - 0
libgearman-1.0/t/cc_test.cc

@@ -0,0 +1,54 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Test C interface
+ *
+ *  Copyright (C) 2011 Data Differential, http://datadifferential.com/ All
+ *  rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <cstdlib>
+#include <libgearman-1.0/gearman.h>
+
+int main(void)
+{
+  gearman_client_st *client= gearman_client_create(NULL);
+
+  if (client == NULL)
+  {
+    return EXIT_FAILURE;
+  }
+
+  gearman_client_free(client);
+
+  return EXIT_SUCCESS;
+}
+

+ 15 - 0
libgearman-1.0/t/include.am

@@ -0,0 +1,15 @@
+# vim:ft=automake
+
+# Test linking with C application
+libgearman_1_0_t_c_test_SOURCES= libgearman-1.0/t/c_test.c
+libgearman_1_0_t_c_test_LDADD= libgearman/libgearman.la
+libgearman_1_0_t_c_test_DEPENDENCIES= libgearman/libgearman.la
+check_PROGRAMS+= libgearman-1.0/t/c_test
+noinst_PROGRAMS+= libgearman-1.0/t/c_test
+
+# Test linking with C application
+libgearman_1_0_t_cc_test_SOURCES= libgearman-1.0/t/cc_test.cc
+libgearman_1_0_t_cc_test_LDADD= libgearman/libgearman.la
+libgearman_1_0_t_cc_test_DEPENDENCIES= libgearman/libgearman.la
+check_PROGRAMS+= libgearman-1.0/t/cc_test
+noinst_PROGRAMS+= libgearman-1.0/t/cc_test

+ 6 - 4
libtest/gearmand.cc

@@ -140,10 +140,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
     {
@@ -190,6 +187,11 @@ public:
     return true;
   }
 
+  bool has_syslog() const
+  {
+    return true;
+  }
+
   bool build(int argc, const char *argv[]);
 };
 
@@ -202,7 +204,7 @@ bool Gearmand::build(int argc, const char *argv[])
     arg_buffer << " -u root ";
   }
 
-  arg_buffer << " --listen=127.0.0.1 ";
+  arg_buffer << " --listen=localhost ";
 
   for (int x= 1 ; x < argc ; x++)
   {

+ 1 - 1
libtest/memcached.cc

@@ -298,7 +298,7 @@ bool Memcached::build(int argc, const char *argv[])
     arg_buffer << " -u root ";
   }
 
-  arg_buffer << " -l 127.0.0.1 ";
+  arg_buffer << " -l localhost ";
   arg_buffer << " -m 128 ";
   arg_buffer << " -M ";
 

+ 12 - 4
libtest/server.cc

@@ -220,17 +220,20 @@ bool Server::start()
     }
   }
 
-  int count= is_helgrind() or is_valgrind() ? 20 : 5;
-  while (not ping() and --count)
+  int counter= 0;
+  bool pinged= false;
+  while ((pinged= ping()) == false and
+         counter < (is_helgrind() or is_valgrind() ? 20 : 5))
   {
-    dream(0, 50000);
+    dream(counter++, 50000);
   }
 
-  if (count == 0)
+  if (pinged == false)
   {
     // If we happen to have a pid file, lets try to kill it
     if (pid_file_option() and pid_file().empty() == false)
     {
+      Error << "We are going to kill it off";
       kill_file(pid_file());
     }
     Error << "Failed to ping() server started with:" << _running;
@@ -387,6 +390,11 @@ bool Server::args(std::string& options)
     arg_buffer << " " << log_file_option() << _log_file;
   }
 
+  if (getenv("LIBTEST_SYSLOG") and has_syslog())
+  {
+    arg_buffer << " --syslog";
+  }
+
   // Update pid_file
   if (pid_file_option())
   {

Some files were not shown because too many files changed in this diff