[Box Backup-commit] COMMIT r1092 - box/chris/merge/lib/common
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Wed, 18 Oct 2006 20:39:04 +0100
Author: chris
Date: 2006-10-18 20:39:04 +0100 (Wed, 18 Oct 2006)
New Revision: 1092
Modified:
box/chris/merge/lib/common/Test.h
Log:
Wait longer for server to die in KillServer (takes about 5 seconds on
my box). (refs #3)
Modified: box/chris/merge/lib/common/Test.h
===================================================================
--- box/chris/merge/lib/common/Test.h 2006-10-16 23:24:56 UTC (rev 1091)
+++ box/chris/merge/lib/common/Test.h 2006-10-18 19:39:04 UTC (rev 1092)
@@ -227,7 +227,7 @@
return statusOk;
}
-inline bool ServerIsAlive()
+inline bool ServerIsAlive(int pid)
{
return SendCommands("");
}
@@ -237,11 +237,9 @@
return SendCommands("reload");
}
-inline bool KillServer(int pid)
+inline bool KillServerInternal(int pid)
{
TEST_THAT(SendCommands("terminate"));
- ::sleep(1);
- return !ServerIsAlive();
}
#else // !WIN32
@@ -258,17 +256,45 @@
return ::kill(pid, SIGHUP) != -1;
}
-inline bool KillServer(int pid)
+inline bool KillServerInternal(int pid)
{
if(pid == 0 || pid == -1) return false;
- bool KilledOK = ::kill(pid, SIGTERM) != -1;
- TEST_THAT(KilledOK);
- ::sleep(1);
- return !ServerIsAlive(pid);
+ TEST_THAT(::kill(pid, SIGTERM) != -1);
}
#endif // WIN32
+inline bool KillServer(int pid)
+{
+ KillServerInternal(pid);
+
+ for (int i = 0; i < 30; i++)
+ {
+ if (!ServerIsAlive(pid)) break;
+ ::sleep(1);
+ if (!ServerIsAlive(pid)) break;
+
+ if (i == 0)
+ {
+ printf("waiting for server to die");
+ }
+ printf(".");
+ fflush(stdout);
+ }
+
+ if (!ServerIsAlive(pid))
+ {
+ printf("done.\n");
+ }
+ else
+ {
+ printf("failed!\n");
+ }
+ fflush(stdout);
+
+ return !ServerIsAlive(pid);
+}
+
inline void TestRemoteProcessMemLeaks(const char *filename)
{
#ifdef BOX_MEMORY_LEAK_TESTING