summaryrefslogtreecommitdiff
path: root/lib/server/ServerControl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/server/ServerControl.cpp')
-rw-r--r--lib/server/ServerControl.cpp78
1 files changed, 70 insertions, 8 deletions
diff --git a/lib/server/ServerControl.cpp b/lib/server/ServerControl.cpp
index b9650cee..f1a718df 100644
--- a/lib/server/ServerControl.cpp
+++ b/lib/server/ServerControl.cpp
@@ -15,13 +15,14 @@
#include <signal.h>
#endif
+#include "BoxTime.h"
+#include "IOStreamGetLine.h"
#include "ServerControl.h"
#include "Test.h"
#ifdef WIN32
#include "WinNamedPipeStream.h"
-#include "IOStreamGetLine.h"
#include "BoxPortsAndFiles.h"
static std::string sPipeName;
@@ -197,18 +198,18 @@ bool KillServer(int pid, bool WaitForProcess)
}
#endif
- for (int i = 0; i < 30; i++)
+ printf("Waiting for server to die (pid %d): ", pid);
+
+ for (int i = 0; i < 300; i++)
{
- if (i == 0)
+ if (i % 10 == 0)
{
- printf("Waiting for server to die (pid %d): ", pid);
+ printf(".");
+ fflush(stdout);
}
- printf(".");
- fflush(stdout);
-
if (!ServerIsAlive(pid)) break;
- ::sleep(1);
+ ShortSleep(MilliSecondsToBoxTime(100), false);
if (!ServerIsAlive(pid)) break;
}
@@ -226,3 +227,64 @@ bool KillServer(int pid, bool WaitForProcess)
return !ServerIsAlive(pid);
}
+bool KillServer(std::string pid_file, bool WaitForProcess)
+{
+ FileStream fs(pid_file);
+ IOStreamGetLine getline(fs);
+ std::string line = getline.GetLine();
+ int pid = atoi(line.c_str());
+ bool status = KillServer(pid, WaitForProcess);
+ TEST_EQUAL_LINE(true, status, std::string("kill(") + pid_file + ")");
+
+#ifdef WIN32
+ if(WaitForProcess)
+ {
+ 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;
+ }
+ }
+#endif
+
+ return status;
+}
+
+int StartDaemon(int current_pid, const std::string& cmd_line, const char* pid_file)
+{
+ TEST_THAT_OR(current_pid == 0, return 0);
+
+ int new_pid = LaunchServer(cmd_line, pid_file);
+ TEST_THAT_OR(new_pid != -1 && new_pid != 0, return 0);
+
+ ::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;
+}
+
+