Merge lp:~jamesodhunt/upstart/fix-test_state-test-reprise into lp:upstart

Proposed by James Hunt on 2013-11-13
Status: Merged
Merged at revision: 1570
Proposed branch: lp:~jamesodhunt/upstart/fix-test_state-test-reprise
Merge into: lp:upstart
Diff against target: 154 lines (+50/-29)
3 files modified
ChangeLog (+12/-0)
init/tests/test_state.c (+21/-4)
test/test_util_common.h (+17/-25)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/fix-test_state-test-reprise
Reviewer Review Type Date Requested Status
Dimitri John Ledkov 2013-11-13 Approve on 2013-11-13
Review via email: mp+195070@code.launchpad.net
To post a comment you must log in.
Dimitri John Ledkov (xnox) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-11-12 12:17:30 +0000
3+++ ChangeLog 2013-11-13 14:27:18 +0000
4@@ -1,3 +1,15 @@
5+2013-11-13 James Hunt <james.hunt@ubuntu.com>
6+
7+ * init/tests/test_state.c: test_log_serialise():
8+ - Added extra checks on nih_io_watches.
9+ - Need to wait for logfile to be written to handle case where
10+ NIH encounters EAGAIN.
11+ * test/test_util_common.h:
12+ - Removed unused macros:
13+ - TEST_FORCE_WATCH_UPDATE_TIMEOUT()
14+ - TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS()
15+ - Added TIMED_BLOCK() macro.
16+
17 2013-11-12 James Hunt <james.hunt@ubuntu.com>
18
19 * extra/man/socket-event.7: PATH => SOCKET_PATH.
20
21=== modified file 'init/tests/test_state.c'
22--- init/tests/test_state.c 2013-10-24 12:35:33 +0000
23+++ init/tests/test_state.c 2013-11-13 14:27:18 +0000
24@@ -2048,12 +2048,15 @@
25 struct stat statbuf;
26 mode_t old_perms;
27 int status;
28+ int got;
29
30 conf_init ();
31+ nih_io_init ();
32 log_unflushed_init ();
33
34 TEST_TRUE (NIH_LIST_EMPTY (conf_sources));
35 TEST_TRUE (NIH_LIST_EMPTY (log_unflushed_files));
36+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
37
38 TEST_GROUP ("Log serialisation and deserialisation");
39
40@@ -2067,6 +2070,7 @@
41
42 log = log_new (NULL, "/foo", pty_master, 0);
43 TEST_NE_P (log, NULL);
44+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
45
46 json = log_serialise (log);
47 TEST_NE_P (json, NULL);
48@@ -2086,11 +2090,14 @@
49
50 TEST_FILENAME (filename);
51
52+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
53+
54 TEST_EQ (openpty (&pty_master, &pty_slave, NULL, NULL, NULL), 0);
55
56 /* Provide a log file which is accessible initially */
57 log = log_new (NULL, filename, pty_master, 0);
58 TEST_NE_P (log, NULL);
59+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
60
61 assert0 (pipe (fds));
62
63@@ -2131,10 +2138,19 @@
64 close (pty_slave);
65 close (fds[0]);
66
67- /* Slurp the childs initial output */
68- TEST_FORCE_WATCH_UPDATE ();
69-
70- TEST_EQ (stat (filename, &statbuf), 0);
71+ TEST_FALSE (NIH_LIST_EMPTY (nih_io_watches));
72+
73+ got = FALSE;
74+ TIMED_BLOCK (5) {
75+ TEST_FORCE_WATCH_UPDATE ();
76+ if (! stat (filename, &statbuf)) {
77+ got = TRUE;
78+ break;
79+ }
80+ sleep (1);
81+ }
82+
83+ TEST_EQ (got, TRUE);
84
85 /* save */
86 old_perms = statbuf.st_mode;
87@@ -2181,6 +2197,7 @@
88
89 nih_free (log);
90 nih_free (new_log);
91+ TEST_TRUE (NIH_LIST_EMPTY (nih_io_watches));
92 TEST_EQ (unlink (filename), 0);
93
94 /*******************************/
95
96=== modified file 'test/test_util_common.h'
97--- test/test_util_common.h 2013-11-12 12:17:30 +0000
98+++ test/test_util_common.h 2013-11-13 14:27:18 +0000
99@@ -142,31 +142,6 @@
100 _TEST_WATCH_UPDATE (1, NULL)
101
102 /**
103- * TEST_FORCE_WATCH_UPDATE_TIMEOUT:
104- * @timeout: struct timeval pointer.
105- *
106- * Force NIH to look for a file event relating to any NihIo objects
107- * within time period @timeout.
108- **/
109-#define TEST_FORCE_WATCH_UPDATE_TIMEOUT(timeout) \
110- _TEST_WATCH_UPDATE (1, timeout)
111-
112-/**
113- * TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS:
114- * @timeout: struct timeval pointer.
115- *
116- * Force NIH to look for a file event relating to any NihIo objects
117- * within time period @timeout.
118- **/
119-#define TEST_FORCE_WATCH_UPDATE_TIMEOUT_SECS(secs) \
120-{ \
121- struct timeval _t; \
122- _t.tv_sec = secs; \
123- _t.tv_usec = 0; \
124- _TEST_WATCH_UPDATE (1, &_t); \
125-}
126-
127-/**
128 * ENSURE_DIRECTORY_EMPTY:
129 * @path: Full path to a directory.
130 *
131@@ -695,6 +670,23 @@
132 #define TEST_STR_ARRAY_NOT_CONTAINS(_array, _pattern) \
133 _TEST_STR_ARRAY_CONTAINS (_array, _pattern, TRUE)
134
135+
136+/**
137+ * TIMED_BLOCK:
138+ * @secs: Seconds to run for.
139+ *
140+ * Run a block of code repeatedly for @secs seconds.
141+ * Have the loop call sleep(3) to avoid a busy wait.
142+ **/
143+#define TIMED_BLOCK(secs) \
144+ for (time_t _start_time = 0, _now = 0, _wait_secs = (time_t)secs;\
145+ ; _now = time (NULL)) \
146+ if (! _start_time) { \
147+ _start_time = _now = time (NULL); \
148+ } else if ((_start_time + _wait_secs) < _now) { \
149+ break; \
150+ } else
151+
152 extern int test_user_mode;
153
154 /* Prototypes */

Subscribers

People subscribed via source and target branches