[Box Backup-commit] COMMIT r1193 - box/chris/merge/test/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Dec 3 10:52:38 GMT 2006


Author: chris
Date: 2006-12-03 10:52:38 +0000 (Sun, 03 Dec 2006)
New Revision: 1193

Modified:
   box/chris/merge/test/common/testcommon.cpp
Log:
Make the timer test reliable by using nanosleep() instead of sleep(), 
since sleep() may use signals and interfere with SIGALRM, and also 
cannot be resumed if interrupted by a signal. (refs #3, refs #9).


Modified: box/chris/merge/test/common/testcommon.cpp
===================================================================
--- box/chris/merge/test/common/testcommon.cpp	2006-12-03 10:41:01 UTC (rev 1192)
+++ box/chris/merge/test/common/testcommon.cpp	2006-12-03 10:52:38 UTC (rev 1193)
@@ -9,7 +9,9 @@
 
 #include "Box.h"
 
+#include <errno.h>
 #include <stdio.h>
+#include <time.h>
 
 #include "Test.h"
 #include "Configuration.h"
@@ -134,6 +136,15 @@
 	0
 };
 
+void safe_sleep(int seconds)
+{
+	struct timespec ts;
+	ts.tv_sec  = seconds;
+	ts.tv_nsec = 0;
+	while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
+	{ /* sleep again */ }
+}
+
 int test(int argc, const char *argv[])
 {
 	// Test self-deleting temporary file streams
@@ -254,13 +265,13 @@
 	TEST_THAT(!t2.HasExpired());
 	TEST_THAT(!t3.HasExpired());
 	
-	sleep(1);
+	safe_sleep(1);
 	TEST_THAT(!t0.HasExpired());
 	TEST_THAT(t1.HasExpired());
 	TEST_THAT(!t2.HasExpired());
 	TEST_THAT(!t3.HasExpired());
 	
-	sleep(1);
+	safe_sleep(1);
 	TEST_THAT(!t0.HasExpired());
 	TEST_THAT(t1.HasExpired());
 	TEST_THAT(t2.HasExpired());
@@ -272,7 +283,7 @@
 	TEST_THAT(!t1.HasExpired());
 	TEST_THAT(!t2.HasExpired());
 	
-	sleep(1);
+	safe_sleep(1);
 	TEST_THAT(!t0.HasExpired());
 	TEST_THAT(t1.HasExpired());
 	TEST_THAT(!t2.HasExpired());




More information about the Boxbackup-commit mailing list