diff options
author | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:39:54 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2015-07-31 06:39:54 +0000 |
commit | 762af2a462607258817fde3dc919ee7db5d1bcf0 (patch) | |
tree | 5871cf32b97f6ce61b51804e620dfe3990003889 /lib/server | |
parent | 74519c6abfeada675dfa0e4d035e45d58f0d9903 (diff) |
Refactor to allow sharing code for starting and stopping daemons in tests.
The new StartDaemon() and StopDaemon() in ServerControl.cpp/h are generic,
and used by StartClient() and StartServer() in StoreTestUtils.cpp/h.
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/ServerControl.cpp | 38 | ||||
-rw-r--r-- | lib/server/ServerControl.h | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp index b9650cee..c698319f 100644 --- a/lib/server/ServerControl.cpp +++ b/lib/server/ServerControl.cpp @@ -226,3 +226,41 @@ bool KillServer(int pid, bool WaitForProcess) return !ServerIsAlive(pid); } +int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file) +{ + TEST_THAT_OR(current_pid == 0, return false); + + int new_pid = LaunchServer(cmd_line, pid_file); + + TEST_THAT_OR(new_pid != -1 && new_pid != 0, return false); + + ::sleep(1); + TEST_THAT_OR(ServerIsAlive(new_pid), return 0); + return new_pid; +} + +bool StopDaemon(int current_pid, const std::string& pid_file, + const std::string& memleaks_file, bool wait_for_process) +{ + TEST_THAT_OR(current_pid != 0, return false); + TEST_THAT_OR(ServerIsAlive(current_pid), return false); + TEST_THAT_OR(KillServer(current_pid, wait_for_process), return false); + ::sleep(1); + + TEST_THAT_OR(!ServerIsAlive(current_pid), return false); + + #ifdef WIN32 + int unlink_result = unlink(pid_file.c_str()); + TEST_EQUAL_LINE(0, unlink_result, std::string("unlink ") + pid_file); + if(unlink_result != 0) + { + return false; + } + #else + TestRemoteProcessMemLeaks(memleaks_file.c_str()); + #endif + + return true; +} + + diff --git a/lib/server/ServerControl.h b/lib/server/ServerControl.h index b2e51864..430f03a3 100644 --- a/lib/server/ServerControl.h +++ b/lib/server/ServerControl.h @@ -5,6 +5,9 @@ bool HUPServer(int pid); bool KillServer(int pid, bool WaitForProcess = false); +int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file); +bool StopDaemon(int current_pid, const std::string& pid_file, + const std::string& memleaks_file, bool wait_for_process); #ifdef WIN32 #include "WinNamedPipeStream.h" |