[Box Backup-commit] COMMIT r1175 - box/chris/merge/lib/common
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Sun, 26 Nov 2006 19:41:12 +0000
Author: chris
Date: 2006-11-26 19:41:12 +0000 (Sun, 26 Nov 2006)
New Revision: 1175
Modified:
box/chris/merge/lib/common/Test.h
Log:
Separate ReadPidFile() out from LaunchServer() in test code (refs #9)
Modified: box/chris/merge/lib/common/Test.h
===================================================================
--- box/chris/merge/lib/common/Test.h 2006-11-26 19:38:46 UTC (rev 1174)
+++ box/chris/merge/lib/common/Test.h 2006-11-26 19:41:12 UTC (rev 1175)
@@ -104,30 +104,19 @@
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;
}
+ int pid = -1;
+
FILE *f = fopen(pidFile, "r");
- int pid = -1;
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 @@
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 @@
}
#endif // TEST__H
-