From: Brian Aker Date: Sat, 14 Jul 2012 19:23:35 +0000 (-0700) Subject: Merge up to gearmand. X-Git-Tag: 1.0.10~4^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=bf755bec1cd09fad086a47650c1a725c9fbc7eb1;p=awesomized%2Flibmemcached Merge up to gearmand. --- diff --git a/libtest/fatal.hpp b/libtest/fatal.hpp index f0ee0813..7a8ce516 100644 --- a/libtest/fatal.hpp +++ b/libtest/fatal.hpp @@ -42,6 +42,13 @@ #define __PRETTY_FUNCTION__ __func__ #endif +#define YATL_STRINGIFY(x) #x +#define YATL_TOSTRING(x) YATL_STRINGIFY(x) +#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__) +#define YATL_AT_PARAM __func__, AT +#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique" +#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func" + #define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__ namespace libtest { diff --git a/libtest/gearmand.cc b/libtest/gearmand.cc index 82953e99..e25cdf74 100644 --- a/libtest/gearmand.cc +++ b/libtest/gearmand.cc @@ -69,11 +69,7 @@ class Gearmand : public libtest::Server { private: public: - Gearmand(const std::string& host_arg, in_port_t port_arg) : - libtest::Server(host_arg, port_arg, GEARMAND_BINARY, true) - { - set_pid_file(); - } + Gearmand(const std::string& host_arg, in_port_t port_arg, const char* binary= GEARMAND_BINARY); bool ping() { @@ -94,7 +90,11 @@ public: gearman_client_free(client); return true; } - Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client); + + if (out_of_ban_killed() == false) + { + Error << hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc) << " extended: " << gearman_client_error(client); + } } else { @@ -145,6 +145,12 @@ public: bool build(size_t argc, const char *argv[]); }; +Gearmand::Gearmand(const std::string& host_arg, in_port_t port_arg, const char* binary_arg) : + libtest::Server(host_arg, port_arg, binary_arg, true) +{ + set_pid_file(); +} + bool Gearmand::build(size_t argc, const char *argv[]) { if (getuid() == 0 or geteuid() == 0) @@ -169,4 +175,9 @@ libtest::Server *build_gearmand(const char *hostname, in_port_t try_port) return new Gearmand(hostname, try_port); } +libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary) +{ + return new Gearmand(hostname, try_port, binary); +} + } diff --git a/libtest/gearmand.h b/libtest/gearmand.h index 0c09774c..49c08c9f 100644 --- a/libtest/gearmand.h +++ b/libtest/gearmand.h @@ -44,4 +44,6 @@ namespace libtest { libtest::Server *build_gearmand(const char *hostname, in_port_t try_port); +libtest::Server *build_gearmand(const char *hostname, in_port_t try_port, const char* binary); + } diff --git a/libtest/main.cc b/libtest/main.cc index 5fa53889..79f177c3 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -316,6 +316,11 @@ int main(int argc, char *argv[]) std::cerr << "std::exception:" << e.what() << std::endl; exit_code= EXIT_FAILURE; } + catch (char const*) + { + std::cerr << "Exception:" << std::endl; + exit_code= EXIT_FAILURE; + } catch (...) { std::cerr << "Unknown exception halted execution." << std::endl; diff --git a/libtest/memcached.cc b/libtest/memcached.cc index b8838a06..d92944f6 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -97,6 +97,7 @@ public: libtest::Server(host_arg, port_arg, MEMCACHED_BINARY, is_memcached_libtool(), is_socket_arg) { + set_pid_file(); } virtual const char *sasl() const @@ -114,13 +115,27 @@ public: return _username; } - virtual bool has_pid_file() const + bool wait_for_pidfile() const { - return false; + Wait wait(pid(), 4); + + return wait.successful(); } 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; diff --git a/libtest/memcached.h b/libtest/memcached.h index 915d3fa8..405f275f 100644 --- a/libtest/memcached.h +++ b/libtest/memcached.h @@ -49,3 +49,4 @@ libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port libtest::Server *build_memcached_sasl_socket(const std::string& socket_file, const in_port_t try_port, const std::string& username, const std::string& password); } + diff --git a/libtest/server.cc b/libtest/server.cc index 99991209..61f8e983 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -99,7 +99,8 @@ Server::Server(const std::string& host_arg, const in_port_t port_arg, _is_socket(is_socket_arg), _port(port_arg), _hostname(host_arg), - _app(executable, _is_libtool) + _app(executable, _is_libtool), + out_of_ban_killed_(false) { } @@ -111,7 +112,6 @@ bool Server::check() { _app.slurp(); _app.check(); - return true; } @@ -401,6 +401,7 @@ bool Server::set_log_file() bool Server::args(Application& app) { + // Set a log file if it was requested (and we can) if (has_log_file_option()) { diff --git a/libtest/server.h b/libtest/server.h index a41e621b..f27ce08f 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -250,6 +250,16 @@ public: bool validate(); + void out_of_ban_killed(bool arg) + { + out_of_ban_killed_= arg; + } + + bool out_of_ban_killed() + { + return out_of_ban_killed_; + } + protected: bool set_pid_file(); Options _options; @@ -262,6 +272,7 @@ private: bool set_log_file(); bool set_socket_file(); void reset_pid(); + bool out_of_ban_killed_; bool args(Application&); std::string _error; diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 6973937b..d8ef5d49 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -75,7 +75,7 @@ void server_startup_st::push_server(Server *arg) } else { - char port_str[NI_MAXSERV]; + char port_str[NI_MAXSERV]= { 0 }; snprintf(port_str, sizeof(port_str), "%u", int(arg->port())); server_config_string+= "--server="; @@ -142,7 +142,7 @@ bool server_startup_st::shutdown() bool success= true; for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { - if ((*iter) and (*iter)->has_pid() and (*iter)->kill() == false) + if ((*iter)->has_pid() and (*iter)->kill() == false) { Error << "Unable to kill:" << *(*iter); success= false; @@ -206,6 +206,16 @@ bool server_startup_st::start_server(const std::string& server_type, in_port_t t } } } + else if (server_type.compare("hostile-gearmand") == 0) + { + if (GEARMAND_BINARY) + { + if (HAVE_LIBGEARMAN) + { + server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand"); + } + } + } else if (server_type.compare("drizzled") == 0) { if (DRIZZLED_BINARY) diff --git a/libtest/timer.cc b/libtest/timer.cc index 0a8d69b5..ffa8a4b6 100644 --- a/libtest/timer.cc +++ b/libtest/timer.cc @@ -35,8 +35,11 @@ */ #include + #include + #include +#include namespace libtest { @@ -45,9 +48,18 @@ std::ostream& operator<<(std::ostream& output, const libtest::Timer& arg) struct timespec temp; arg.difference(temp); - output << temp.tv_sec; + if (temp.tv_sec > 60) + { + output << temp.tv_sec / 60; + output << "." << temp.tv_sec % 60; + } + else + { + output << temp.tv_sec; + } + output << ":"; - output << temp.tv_nsec; + output << std::setfill('0') << std::setw(9) << temp.tv_nsec; return output; } diff --git a/libtest/timer.hpp b/libtest/timer.hpp index 37da32f1..28ec4741 100644 --- a/libtest/timer.hpp +++ b/libtest/timer.hpp @@ -36,8 +36,9 @@ #pragma once +#include #include -#include +#include #ifdef __MACH__ # include @@ -72,11 +73,34 @@ public: _time(_end); } + void offset(int64_t minutes_arg, int64_t seconds_arg, int64_t nanoseconds) + { + reset(); + _end= _begin; + _end.tv_sec+= (minutes_arg * 60) +seconds_arg; + _end.tv_nsec+= nanoseconds; + } + + int64_t minutes() + { + struct timespec result; + difference(result); + return int64_t(result.tv_sec / 60); + } + + uint64_t elapsed_milliseconds() const + { + struct timespec temp; + difference(temp); + + return temp.tv_sec*1000 +temp.tv_nsec/1000000; + } + void difference(struct timespec& arg) const { if ((_end.tv_nsec -_begin.tv_nsec) < 0) { - arg.tv_sec= _end.tv_sec -_begin.tv_sec-1; + arg.tv_sec= _end.tv_sec -_begin.tv_sec -1; arg.tv_nsec= 1000000000 +_end.tv_nsec -_begin.tv_nsec; } diff --git a/libtest/unittest.cc b/libtest/unittest.cc index c0381f4d..b68669f5 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -726,6 +726,21 @@ static test_return_t check_dns_TEST(void *) return TEST_SUCCESS; } +static test_return_t Timer_TEST(void *) +{ + int64_t minutes= random() % 50; + minutes++; + + Timer check; + + check.reset(); + check.offset(minutes, 2, 200); + + test_compare(check.minutes(), minutes); + + return TEST_SUCCESS; +} + static test_return_t lookup_true_TEST(void *) { test_warn(libtest::lookup("exist.gearman.info"), "dns is not currently working"); @@ -913,6 +928,11 @@ test_st create_tmpfile_TESTS[] ={ {0, 0, 0} }; +test_st timer_TESTS[] ={ + {"libtest::Timer", 0, Timer_TEST }, + {0, 0, 0} +}; + test_st dns_TESTS[] ={ {"libtest::lookup(true)", 0, lookup_true_TEST }, {"libtest::lookup(false)", 0, lookup_false_TEST }, @@ -979,6 +999,7 @@ collection_st collection[] ={ {"number_of_cpus()", 0, 0, number_of_cpus_TESTS }, {"create_tmpfile()", 0, 0, create_tmpfile_TESTS }, {"dns", 0, 0, dns_TESTS }, + {"libtest::Timer", 0, 0, timer_TESTS }, {0, 0, 0, 0} };