From 45bd4941b48480653534255cee795684ed230084 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Sat, 20 Aug 2011 15:18:58 -0700 Subject: [PATCH] Abstract out the wait --- libtest/memcached.cc | 16 ++++------------ libtest/server.cc | 7 +++++++ libtest/server.h | 2 ++ libtest/wait.h | 6 ++++++ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 3e8e3fcd..daf6787c 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -87,9 +87,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (error_is_ok and not wait.successful()) + if (error_is_ok and not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -120,9 +118,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (not wait.successful()) + if (not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -230,9 +226,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (error_is_ok and not wait.successful()) + if (error_is_ok and not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; @@ -263,9 +257,7 @@ public: // Memcached is slow to start, so we need to do this if (not pid_file().empty()) { - Wait wait(pid_file(), 0); - - if (not wait.successful()) + if (not wait_for_pidfile()) { Error << "Pidfile was not found:" << pid_file(); return -1; diff --git a/libtest/server.cc b/libtest/server.cc index 5f0d59ec..8b8b8f3e 100644 --- a/libtest/server.cc +++ b/libtest/server.cc @@ -155,6 +155,13 @@ bool Server::command(std::string& command_arg) return false; } +bool Server::wait_for_pidfile() const +{ + Wait wait(pid_file(), 4); + + return wait.successful(); +} + bool Server::start() { // If we find that we already have a pid then kill it. diff --git a/libtest/server.h b/libtest/server.h index 123d1c32..b91f55b1 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -148,6 +148,8 @@ public: return (_pid > 1); } + bool wait_for_pidfile() const; + bool check_pid(pid_t pid_arg) const { return (pid_arg > 1); diff --git a/libtest/wait.h b/libtest/wait.h index d72a897b..391afa49 100644 --- a/libtest/wait.h +++ b/libtest/wait.h @@ -38,6 +38,12 @@ public: uint32_t this_wait; uint32_t retry; + if (filename.empty()) + { + _successful= false; + return; + } + for (waited= 0, retry= 1; ; retry++, waited+= this_wait) { if (access(filename.c_str(), R_OK) == 0) -- 2.30.2