James Hunt has proposed merging lp:~jamesodhunt/upstart/fix-test_state-test into lp:upstart.
Requested reviews: Upstart Reviewers (upstart-reviewers) For more details, see: https://code.launchpad.net/~jamesodhunt/upstart/fix-test_state-test/+merge/195031 -- https://code.launchpad.net/~jamesodhunt/upstart/fix-test_state-test/+merge/195031 Your team Upstart Reviewers is requested to review the proposed merge of lp:~jamesodhunt/upstart/fix-test_state-test into lp:upstart.
=== modified file 'ChangeLog' --- ChangeLog 2013-11-12 12:17:30 +0000 +++ ChangeLog 2013-11-13 11:07:42 +0000 @@ -1,3 +1,11 @@ +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.c: Added timed_check() utility function. + 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 11:07:42 +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; + while (timed_check (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.c' --- test/test_util_common.c 2013-11-12 12:17:30 +0000 +++ test/test_util_common.c 2013-11-13 11:07:42 +0000 @@ -1002,3 +1002,37 @@ } } + +/** + * timed_check: + * @secs: Seconds to run for. + * + * Return TRUE for @secs seconds. Place in a while loop to call a block + * of code repeatedly for that duration (have the loop call sleep(3) to + * avoid a busy wait!). + * + * Returns: TRUE whilst @secs timeout has not been reached, else FALSE. + **/ +int +timed_check (int secs) +{ + static time_t start_time = 0; + static int secs_to_wait = 0; + time_t now; + + if (! secs) + return FALSE; + + if (! start_time) + start_time = time (NULL); + + if (! secs_to_wait) + secs_to_wait = secs; + + now = time (NULL); + + if (now > (start_time + secs_to_wait)) + return FALSE; + + return TRUE; +} === 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 11:07:42 +0000 @@ -756,4 +756,7 @@ void test_common_cleanup (void); +int timed_check (int secs) + __attribute__ ((warn_unused_result)); + #endif /* TEST_UTIL_COMMON_H */
-- upstart-devel mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/upstart-devel
