James Hunt has proposed merging 
lp:~jamesodhunt/upstart/fix-test_state-test-reprise into lp:upstart.

Requested reviews:
  Upstart Reviewers (upstart-reviewers)

For more details, see:
https://code.launchpad.net/~jamesodhunt/upstart/fix-test_state-test-reprise/+merge/195070
-- 
https://code.launchpad.net/~jamesodhunt/upstart/fix-test_state-test-reprise/+merge/195070
Your team Upstart Reviewers is requested to review the proposed merge of 
lp:~jamesodhunt/upstart/fix-test_state-test-reprise into lp:upstart.
=== modified file 'ChangeLog'
--- ChangeLog	2013-11-12 12:17:30 +0000
+++ ChangeLog	2013-11-13 14:27:18 +0000
@@ -1,3 +1,15 @@
+2013-11-13  James Hunt  <[email protected]>
+
+	* init/tests/test_state.c: test_log_serialise():
+	  - Added extra checks on nih_io_watches.
+	  - Need to wait for logfile to be written to handle case where
+	    NIH encounters EAGAIN.
+	* test/test_util_common.h:
+	  - Removed unused macros:
+	    - TEST_FORCE_WATCH_UPDATE_TIMEOUT()
+	    - TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS()
+	  - Added TIMED_BLOCK() macro.
+
 2013-11-12  James Hunt  <[email protected]>
 
 	* extra/man/socket-event.7: PATH => SOCKET_PATH.

=== modified file 'init/tests/test_state.c'
--- init/tests/test_state.c	2013-10-24 12:35:33 +0000
+++ init/tests/test_state.c	2013-11-13 14:27:18 +0000
@@ -2048,12 +2048,15 @@
 	struct stat      statbuf;
 	mode_t           old_perms;
 	int              status;
+	int              got;
 
 	conf_init ();
+	nih_io_init ();
 	log_unflushed_init ();
 
 	TEST_TRUE (NIH_LIST_EMPTY (conf_sources));
 	TEST_TRUE (NIH_LIST_EMPTY (log_unflushed_files));
+	TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
 
 	TEST_GROUP ("Log serialisation and deserialisation");
 
@@ -2067,6 +2070,7 @@
 
 	log = log_new (NULL, "/foo", pty_master, 0);
 	TEST_NE_P (log, NULL);
+	TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
 
 	json = log_serialise (log);
 	TEST_NE_P (json, NULL);
@@ -2086,11 +2090,14 @@
 
 	TEST_FILENAME (filename);
 
+	TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
+
 	TEST_EQ (openpty (&pty_master, &pty_slave, NULL, NULL, NULL), 0);
 
 	/* Provide a log file which is accessible initially */
 	log = log_new (NULL, filename, pty_master, 0);
 	TEST_NE_P (log, NULL);
+	TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
 
 	assert0 (pipe (fds));
 
@@ -2131,10 +2138,19 @@
 	close (pty_slave);
 	close (fds[0]);
 
-	/* Slurp the childs initial output */
-	TEST_FORCE_WATCH_UPDATE ();
-
-	TEST_EQ (stat (filename, &statbuf), 0);
+	TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
+
+	got = FALSE;
+	TIMED_BLOCK (5) {
+		TEST_FORCE_WATCH_UPDATE ();
+		if (! stat (filename, &statbuf)) {
+			got = TRUE;
+			break;
+		}
+		sleep (1);
+	}
+
+	TEST_EQ (got, TRUE);
 
 	/* save */
 	old_perms = statbuf.st_mode;
@@ -2181,6 +2197,7 @@
 
 	nih_free (log);
 	nih_free (new_log);
+	TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
 	TEST_EQ (unlink (filename), 0);
 
 	/*******************************/

=== modified file 'test/test_util_common.h'
--- test/test_util_common.h	2013-11-12 12:17:30 +0000
+++ test/test_util_common.h	2013-11-13 14:27:18 +0000
@@ -142,31 +142,6 @@
 	_TEST_WATCH_UPDATE (1, NULL)
 
 /**
- * TEST_FORCE_WATCH_UPDATE_TIMEOUT:
- * @timeout: struct timeval pointer.
- *
- * Force NIH to look for a file event relating to any NihIo objects
- * within time period @timeout.
- **/
-#define TEST_FORCE_WATCH_UPDATE_TIMEOUT(timeout)                     \
-	_TEST_WATCH_UPDATE (1, timeout)
-
-/**
- * TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS:
- * @timeout: struct timeval pointer.
- *
- * Force NIH to look for a file event relating to any NihIo objects
- * within time period @timeout.
- **/
-#define TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS(secs)                   \
-{                                                                    \
-	struct timeval _t;                                           \
-	_t.tv_sec  = secs;                                           \
-	_t.tv_usec = 0;                                              \
-	_TEST_WATCH_UPDATE (1, &_t);                                 \
-}
-
-/**
  * ENSURE_DIRECTORY_EMPTY:
  * @path: Full path to a directory.
  *
@@ -695,6 +670,23 @@
 #define TEST_STR_ARRAY_NOT_CONTAINS(_array, _pattern)                \
         _TEST_STR_ARRAY_CONTAINS (_array, _pattern, TRUE)
 
+
+/**
+ * TIMED_BLOCK:
+ * @secs: Seconds to run for.
+ *
+ * Run a block of code repeatedly for @secs seconds.
+ * Have the loop call sleep(3) to avoid a busy wait.
+ **/
+#define TIMED_BLOCK(secs)                                                \
+	for (time_t _start_time = 0, _now = 0, _wait_secs = (time_t)secs;\
+		; _now = time (NULL))                                    \
+		if (! _start_time) {                                     \
+			_start_time = _now = time (NULL);                \
+		} else if ((_start_time + _wait_secs) < _now) {          \
+			break;                                           \
+		} else
+
 extern int test_user_mode;
 
 /* Prototypes */

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to