From: Brian Aker Date: Tue, 19 Jun 2012 00:15:21 +0000 (-0700) Subject: Update for fix for testing if memcached is running. X-Git-Tag: 1.0.9~15 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=2d9bd6ba5e72099ae4c5287ade99300c7f6bd1b7;p=awesomized%2Flibmemcached Update for fix for testing if memcached is running. --- diff --git a/libmemcachedutil/ping.cc b/libmemcachedutil/ping.cc index b2192a1d..0154b530 100644 --- a/libmemcachedutil/ping.cc +++ b/libmemcachedutil/ping.cc @@ -54,6 +54,8 @@ bool libmemcached_util_ping(const char *hostname, in_port_t port, memcached_retu return false; } + (void)memcached_behavior_set(memc_ptr, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 400000); + memcached_return_t rc= memcached_server_add(memc_ptr, hostname, port); if (memcached_success(rc)) { diff --git a/libtest/memcached.cc b/libtest/memcached.cc index adf650f8..b8838a06 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -97,7 +97,6 @@ public: libtest::Server(host_arg, port_arg, MEMCACHED_BINARY, is_memcached_libtool(), is_socket_arg) { - set_pid_file(); } virtual const char *sasl() const @@ -115,27 +114,13 @@ public: return _username; } - bool wait_for_pidfile() const + virtual bool has_pid_file() const { - Wait wait(pid(), 4); - - return wait.successful(); + return false; } 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() << " :" << running(); - return -1; - } - } -#endif - memcached_return_t rc; bool ret; @@ -150,7 +135,7 @@ public: if (memcached_failed(rc) or ret == false) { - Error << "libmemcached_util_ping(" << hostname() << ", " << port() << ") error: " << memcached_strerror(NULL, rc); + error(memcached_strerror(NULL, rc)); } return ret; @@ -332,16 +317,6 @@ public: bool ping() { - // 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(); - return -1; - } - } - memcached_return_t rc; bool ret; @@ -356,7 +331,7 @@ public: if (memcached_failed(rc) or ret == false) { - Error << "libmemcached_util_ping2(" << hostname() << ", " << port() << ", " << username() << ", " << password() << ") error: " << memcached_strerror(NULL, rc); + error(memcached_strerror(NULL, rc)); } return ret; diff --git a/libtest/server.cc b/libtest/server.cc index 78b729f9..a5d801a6 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -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 @@ -206,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()); } } } @@ -406,6 +415,7 @@ bool Server::args(Application& app) } // Update pid_file + if (has_pid_file()) { if (_pid_file.empty() and set_pid_file() == false) { diff --git a/libtest/server.h b/libtest/server.h index 2f9fa2f1..736810be 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -210,6 +210,21 @@ public: bool has_pid() const; + virtual bool has_pid_file() const + { + return true; + } + + const std::string& error() + { + return _error; + } + + void error(std::string arg) + { + _error= arg; + } + virtual bool wait_for_pidfile() const; bool check_pid(pid_t pid_arg) const @@ -249,6 +264,7 @@ private: bool set_log_file(); bool set_socket_file(); void reset_pid(); + std::string _error; }; std::ostream& operator<<(std::ostream& output, const libtest::Server &arg); diff --git a/tests/libmemcached-1.0/parser.cc b/tests/libmemcached-1.0/parser.cc index 03fb73ff..3cacd26c 100644 --- a/tests/libmemcached-1.0/parser.cc +++ b/tests/libmemcached-1.0/parser.cc @@ -748,7 +748,9 @@ test_return_t regression_bug_71231153_connect(memcached_st *) test_return_t regression_bug_71231153_poll(memcached_st *) { if (libmemcached_util_ping("10.0.2.252", 0, NULL)) // If for whatever reason someone has a host at this address, skip + { return TEST_SKIPPED; + } { // Test the poll timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));