diff options
author | Chris Wilson <chris+github@qwirx.com> | 2006-11-26 19:41:12 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2006-11-26 19:41:12 +0000 |
commit | c83d51cd16dd979273a960f8ac9375e10fa93942 (patch) | |
tree | 12bc008245cd1abcb692f8d9f9f8ae68d5716e6e /lib/common/Test.h | |
parent | acbafe4f76e88aefd0b57084c77c9b8cbbecbbc9 (diff) |
Separate ReadPidFile() out from LaunchServer() in test code (refs #9)
Diffstat (limited to 'lib/common/Test.h')
-rw-r--r-- | lib/common/Test.h | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/common/Test.h b/lib/common/Test.h index 3c7b00fd..ada42eb2 100644 --- a/lib/common/Test.h +++ b/lib/common/Test.h @@ -104,30 +104,19 @@ inline int RunCommand(const char *pCommandLine) return ::system(command.c_str()); } -inline int LaunchServer(const char *pCommandLine, const char *pidFile) +inline int ReadPidFile(const char *pidFile) { - if(RunCommand(pCommandLine) != 0) - { - printf("Server: %s\n", pCommandLine); - TEST_FAIL_WITH_MESSAGE("Couldn't start server"); - return -1; - } - // time for it to start up - ::sleep(1); - - // read pid file if(!TestFileExists(pidFile)) { - printf("Server: %s\n", pCommandLine); TEST_FAIL_WITH_MESSAGE("Server didn't save PID file"); return -1; } - FILE *f = fopen(pidFile, "r"); int pid = -1; + + FILE *f = fopen(pidFile, "r"); if(f == NULL || fscanf(f, "%d", &pid) != 1) { - printf("Server: %s (pidfile %s)\n", pCommandLine, pidFile); TEST_FAIL_WITH_MESSAGE("Couldn't read PID file"); return -1; } @@ -136,6 +125,30 @@ inline int LaunchServer(const char *pCommandLine, const char *pidFile) return pid; } +inline int LaunchServer(const char *pCommandLine, const char *pidFile) +{ + if(RunCommand(pCommandLine) != 0) + { + printf("Server: %s\n", pCommandLine); + TEST_FAIL_WITH_MESSAGE("Couldn't start server"); + return -1; + } + + // give it time to start up + ::sleep(1); + + // read pid file + int pid = ReadPidFile(pidFile); + + if(pid == -1) + { + // helps with debugging: + printf("Server: %s (pidfile %s)\n", pCommandLine, pidFile); + } + + return pid; +} + #ifdef WIN32 #include "WinNamedPipeStream.h" @@ -335,4 +348,3 @@ inline void TestRemoteProcessMemLeaks(const char *filename) } #endif // TEST__H - |