Merge lp:~vorlon/upstart/upstart-fix-racy-tests into lp:upstart

Proposed by Steve Langasek on 2016-05-02
Status: Merged
Merged at revision: 1668
Proposed branch: lp:~vorlon/upstart/upstart-fix-racy-tests
Merge into: lp:upstart
Diff against target: 136 lines (+37/-5)
2 files modified
ChangeLog (+7/-0)
init/tests/test_job_process.c (+30/-5)
To merge this branch: bzr merge lp:~vorlon/upstart/upstart-fix-racy-tests
Reviewer Review Type Date Requested Status
Martin Pitt (community) 2016-05-02 Approve on 2016-05-02
Dimitri John Ledkov 2016-05-02 Pending
Upstart Reviewers 2016-05-02 Pending
Review via email: mp+293563@code.launchpad.net

Description of the change

Adjust the script-oriented logging tests to use read from a fifo instead of
sleep 999, for clearer process handling; and fix the descriptions of a
couple of tests to match what they're actually doing.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2015-05-12 15:46:47 +0000
3+++ ChangeLog 2016-05-02 19:59:01 +0000
4@@ -1,3 +1,10 @@
5+2016-05-02 Steve Langasek <steve.langasek@ubuntu.com>
6+
7+ * init/tests/test_job_process.c: Adjust the script-oriented logging
8+ tests to use read from a fifo instead of sleep 999, for clearer
9+ process handling; and fix the descriptions of a couple of tests to
10+ match what they're actually doing.
11+
12 2015-05-12 James Hunt <james.hunt@ubuntu.com>
13
14 * init/log.c:
15
16=== modified file 'init/tests/test_job_process.c'
17--- init/tests/test_job_process.c 2014-07-14 12:06:30 +0000
18+++ init/tests/test_job_process.c 2016-05-02 19:59:01 +0000
19@@ -494,6 +494,7 @@
20 FILE *output;
21 struct stat statbuf;
22 char filename[PATH_MAX], buf[80];
23+ char fifoname[PATH_MAX];
24 char function[PATH_MAX];
25 int status;
26 siginfo_t info;
27@@ -1729,6 +1730,13 @@
28 TEST_FEATURE ("with single-line script that is killed");
29 TEST_HASH_EMPTY (job_classes);
30
31+ /* Create a fifo that we can use to read from in our scripts,
32+ * so we have a sensible way to block in shell without spawning
33+ * a separate process.
34+ */
35+ TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
36+ TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
37+
38 class = job_class_new (NULL, "test", NULL);
39 TEST_NE_P (class, NULL);
40
41@@ -1738,7 +1746,7 @@
42 class->process[PROCESS_MAIN] = process_new (class);
43 class->process[PROCESS_MAIN]->command = nih_sprintf (
44 class->process[PROCESS_MAIN],
45- "%s hello world;sleep 999", TEST_CMD_ECHO);
46+ "%s hello world;read <%s", TEST_CMD_ECHO, fifoname);
47 class->process[PROCESS_MAIN]->script = TRUE;
48
49 job = job_new (class, "");
50@@ -1807,6 +1815,7 @@
51 fclose (output);
52
53 TEST_EQ (unlink (filename), 0);
54+ TEST_EQ (unlink (fifoname), 0);
55 nih_free (class);
56
57 /************************************************************/
58@@ -1913,6 +1922,13 @@
59 TEST_FEATURE ("with multi-line script that is killed");
60 TEST_HASH_EMPTY (job_classes);
61
62+ /* Create a fifo that we can use to read from in our scripts,
63+ * so we have a sensible way to block in shell without spawning
64+ * a separate process.
65+ */
66+ TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
67+ TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
68+
69 /* Note we can't use TEST_ALLOC_FAIL() for this test since on
70 * the ENOMEM loop all we could do is discard the error and
71 * continue since job_process_start() calls job_process_spawn()
72@@ -1932,7 +1948,7 @@
73 class->process[PROCESS_MAIN] = process_new (class);
74 class->process[PROCESS_MAIN]->command = nih_sprintf (
75 class->process[PROCESS_MAIN],
76- "%s hello world\nsleep 999", TEST_CMD_ECHO);
77+ "%s hello world\nread <%s", TEST_CMD_ECHO, fifoname);
78 class->process[PROCESS_MAIN]->script = TRUE;
79
80 job = job_new (class, "");
81@@ -1982,12 +1998,20 @@
82 fclose (output);
83
84 TEST_EQ (unlink (filename), 0);
85+ TEST_EQ (unlink (fifoname), 0);
86 nih_free (class);
87
88 /************************************************************/
89 TEST_FEATURE ("with single-line script that writes 1 byte and is killed");
90 TEST_HASH_EMPTY (job_classes);
91
92+ /* Create a fifo that we can use to read from in our scripts,
93+ * so we have a sensible way to block in shell without spawning
94+ * a separate process.
95+ */
96+ TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
97+ TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
98+
99 class = job_class_new (NULL, "test", NULL);
100 TEST_NE_P (class, NULL);
101
102@@ -1997,7 +2021,7 @@
103 class->process[PROCESS_MAIN] = process_new (class);
104 class->process[PROCESS_MAIN]->command = nih_sprintf (
105 class->process[PROCESS_MAIN],
106- "%s -ne X;sleep 999", TEST_CMD_ECHO);
107+ "%s -ne X; read <%s", TEST_CMD_ECHO, fifoname);
108 class->process[PROCESS_MAIN]->script = TRUE;
109
110 job = job_new (class, "");
111@@ -2043,6 +2067,7 @@
112 fclose (output);
113
114 TEST_EQ (unlink (filename), 0);
115+ TEST_EQ (unlink (fifoname), 0);
116 nih_free (class);
117
118 /************************************************************/
119@@ -2055,7 +2080,7 @@
120 */
121
122 /************************************************************/
123- TEST_FEATURE ("with multi-line script that writes 1 byte and is killed");
124+ TEST_FEATURE ("with multi-line script that writes 1 byte");
125 TEST_HASH_EMPTY (job_classes);
126
127 class = job_class_new (NULL, "multiline", NULL);
128@@ -2588,7 +2613,7 @@
129 class->process[PROCESS_MAIN]->command = nih_sprintf (
130 class->process[PROCESS_MAIN],
131 "%s if=/dev/zero of=/dev/null bs=1 count=0", TEST_CMD_DD);
132- class->process[PROCESS_MAIN]->script = TRUE;
133+ class->process[PROCESS_MAIN]->script = FALSE;
134
135 job = job_new (class, "");
136 job->goal = JOB_START;

Subscribers

People subscribed via source and target branches