From 45c6b15d970aca4fa5619b2ba501c1b0f1d89006 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 7 Apr 2012 17:22:59 -0700 Subject: [PATCH] Update libtest. --- libtest/cmdline.cc | 3 ++- libtest/cmdline.h | 5 +++++ libtest/memcached.cc | 3 ++- libtest/server.cc | 36 ++++++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libtest/cmdline.cc b/libtest/cmdline.cc index f6d1e3d6..cbc9d0a6 100644 --- a/libtest/cmdline.cc +++ b/libtest/cmdline.cc @@ -244,8 +244,9 @@ Application::error_t Application::run(const char *args[]) stdout_fd.close(Application::Pipe::WRITE); stderr_fd.close(Application::Pipe::WRITE); - if (spawn_ret) + if (spawn_ret != 0) { + Error << strerror(spawn_ret) << "(" << spawn_ret << ")"; _pid= -1; return Application::INVALID; } diff --git a/libtest/cmdline.h b/libtest/cmdline.h index a387bcf5..12086b0f 100644 --- a/libtest/cmdline.h +++ b/libtest/cmdline.h @@ -90,6 +90,11 @@ public: return _stderr_buffer; } + const char* stderr_c_str() const + { + return &_stderr_buffer[0]; + } + size_t stderr_result_length() const { return _stderr_buffer.size(); diff --git a/libtest/memcached.cc b/libtest/memcached.cc index ffb21c9d..e634df63 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -134,9 +134,10 @@ public: ret= libmemcached_util_ping(hostname().c_str(), port(), &rc); } - if (memcached_failed(rc) or not ret) + if (memcached_failed(rc) or ret == false) { Error << "libmemcached_util_ping(" << hostname() << ", " << port() << ") error: " << memcached_strerror(NULL, rc); + abort(); } return ret; diff --git a/libtest/server.cc b/libtest/server.cc index 3141eed9..c1d01c74 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -182,15 +182,24 @@ bool Server::start() dream(5, 50000); } - 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) { - throw libtest::fatal(LIBYATL_DEFAULT_PARAM, - "Unable to open pidfile for: %s", - _running.c_str()); + Wait wait(pid_file(), 8); + + if (wait.successful() == false) + { + if (_app.check()) + { + continue; + } + + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, + "Unable to open pidfile for: %s", + _running.c_str()); + } } } @@ -220,19 +229,22 @@ bool Server::start() if (pinged == false) { // If we happen to have a pid file, lets try to kill it - if (pid_file().empty() == false) + if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0)) { if (kill_file(pid_file()) == false) { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Failed to kill off server after startup occurred, when pinging failed: %s", pid_file().c_str()); } - Error << "Failed to ping(), waited:" << this_wait - << " server started, having pid_file. exec:" << _running - << " error:" << _app.stderr_result(); + + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, + "Failed to ping(), waited: %u server started, having pid_file. exec: %s error:%s", + this_wait, _running.c_str(), _app.stderr_c_str()); } else { - Error << "Failed to ping() server started. exec:" << _running; + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, + "Failed to ping() server started. exec: %s", + _running.c_str()); } _running.clear(); return false; -- 2.30.2