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

Proposed by Steve Langasek
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) Approve
Dimitri John Ledkov Pending
Upstart Reviewers 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.
Revision history for this message
Steve Langasek (vorlon) wrote :
Revision history for this message
Martin Pitt (pitti) wrote :

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2015-05-12 15:46:47 +0000
+++ ChangeLog 2016-05-02 19:59:01 +0000
@@ -1,3 +1,10 @@
12016-05-02 Steve Langasek <steve.langasek@ubuntu.com>
2
3 * init/tests/test_job_process.c: Adjust the script-oriented logging
4 tests to use read from a fifo instead of sleep 999, for clearer
5 process handling; and fix the descriptions of a couple of tests to
6 match what they're actually doing.
7
12015-05-12 James Hunt <james.hunt@ubuntu.com>82015-05-12 James Hunt <james.hunt@ubuntu.com>
29
3 * init/log.c:10 * init/log.c:
411
=== modified file 'init/tests/test_job_process.c'
--- init/tests/test_job_process.c 2014-07-14 12:06:30 +0000
+++ init/tests/test_job_process.c 2016-05-02 19:59:01 +0000
@@ -494,6 +494,7 @@
494 FILE *output;494 FILE *output;
495 struct stat statbuf;495 struct stat statbuf;
496 char filename[PATH_MAX], buf[80];496 char filename[PATH_MAX], buf[80];
497 char fifoname[PATH_MAX];
497 char function[PATH_MAX];498 char function[PATH_MAX];
498 int status;499 int status;
499 siginfo_t info;500 siginfo_t info;
@@ -1729,6 +1730,13 @@
1729 TEST_FEATURE ("with single-line script that is killed");1730 TEST_FEATURE ("with single-line script that is killed");
1730 TEST_HASH_EMPTY (job_classes);1731 TEST_HASH_EMPTY (job_classes);
17311732
1733 /* Create a fifo that we can use to read from in our scripts,
1734 * so we have a sensible way to block in shell without spawning
1735 * a separate process.
1736 */
1737 TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
1738 TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
1739
1732 class = job_class_new (NULL, "test", NULL);1740 class = job_class_new (NULL, "test", NULL);
1733 TEST_NE_P (class, NULL);1741 TEST_NE_P (class, NULL);
17341742
@@ -1738,7 +1746,7 @@
1738 class->process[PROCESS_MAIN] = process_new (class);1746 class->process[PROCESS_MAIN] = process_new (class);
1739 class->process[PROCESS_MAIN]->command = nih_sprintf (1747 class->process[PROCESS_MAIN]->command = nih_sprintf (
1740 class->process[PROCESS_MAIN],1748 class->process[PROCESS_MAIN],
1741 "%s hello world;sleep 999", TEST_CMD_ECHO);1749 "%s hello world;read <%s", TEST_CMD_ECHO, fifoname);
1742 class->process[PROCESS_MAIN]->script = TRUE;1750 class->process[PROCESS_MAIN]->script = TRUE;
17431751
1744 job = job_new (class, "");1752 job = job_new (class, "");
@@ -1807,6 +1815,7 @@
1807 fclose (output);1815 fclose (output);
18081816
1809 TEST_EQ (unlink (filename), 0);1817 TEST_EQ (unlink (filename), 0);
1818 TEST_EQ (unlink (fifoname), 0);
1810 nih_free (class);1819 nih_free (class);
18111820
1812 /************************************************************/1821 /************************************************************/
@@ -1913,6 +1922,13 @@
1913 TEST_FEATURE ("with multi-line script that is killed");1922 TEST_FEATURE ("with multi-line script that is killed");
1914 TEST_HASH_EMPTY (job_classes);1923 TEST_HASH_EMPTY (job_classes);
19151924
1925 /* Create a fifo that we can use to read from in our scripts,
1926 * so we have a sensible way to block in shell without spawning
1927 * a separate process.
1928 */
1929 TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
1930 TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
1931
1916 /* Note we can't use TEST_ALLOC_FAIL() for this test since on1932 /* Note we can't use TEST_ALLOC_FAIL() for this test since on
1917 * the ENOMEM loop all we could do is discard the error and1933 * the ENOMEM loop all we could do is discard the error and
1918 * continue since job_process_start() calls job_process_spawn()1934 * continue since job_process_start() calls job_process_spawn()
@@ -1932,7 +1948,7 @@
1932 class->process[PROCESS_MAIN] = process_new (class);1948 class->process[PROCESS_MAIN] = process_new (class);
1933 class->process[PROCESS_MAIN]->command = nih_sprintf (1949 class->process[PROCESS_MAIN]->command = nih_sprintf (
1934 class->process[PROCESS_MAIN],1950 class->process[PROCESS_MAIN],
1935 "%s hello world\nsleep 999", TEST_CMD_ECHO);1951 "%s hello world\nread <%s", TEST_CMD_ECHO, fifoname);
1936 class->process[PROCESS_MAIN]->script = TRUE;1952 class->process[PROCESS_MAIN]->script = TRUE;
19371953
1938 job = job_new (class, "");1954 job = job_new (class, "");
@@ -1982,12 +1998,20 @@
1982 fclose (output);1998 fclose (output);
19831999
1984 TEST_EQ (unlink (filename), 0);2000 TEST_EQ (unlink (filename), 0);
2001 TEST_EQ (unlink (fifoname), 0);
1985 nih_free (class);2002 nih_free (class);
19862003
1987 /************************************************************/2004 /************************************************************/
1988 TEST_FEATURE ("with single-line script that writes 1 byte and is killed");2005 TEST_FEATURE ("with single-line script that writes 1 byte and is killed");
1989 TEST_HASH_EMPTY (job_classes);2006 TEST_HASH_EMPTY (job_classes);
19902007
2008 /* Create a fifo that we can use to read from in our scripts,
2009 * so we have a sensible way to block in shell without spawning
2010 * a separate process.
2011 */
2012 TEST_GT (sprintf (fifoname, "%s/pipe", dirname), 0);
2013 TEST_EQ (mknod (fifoname, S_IFIFO|S_IRUSR|S_IWUSR, 0), 0);
2014
1991 class = job_class_new (NULL, "test", NULL);2015 class = job_class_new (NULL, "test", NULL);
1992 TEST_NE_P (class, NULL);2016 TEST_NE_P (class, NULL);
19932017
@@ -1997,7 +2021,7 @@
1997 class->process[PROCESS_MAIN] = process_new (class);2021 class->process[PROCESS_MAIN] = process_new (class);
1998 class->process[PROCESS_MAIN]->command = nih_sprintf (2022 class->process[PROCESS_MAIN]->command = nih_sprintf (
1999 class->process[PROCESS_MAIN],2023 class->process[PROCESS_MAIN],
2000 "%s -ne X;sleep 999", TEST_CMD_ECHO);2024 "%s -ne X; read <%s", TEST_CMD_ECHO, fifoname);
2001 class->process[PROCESS_MAIN]->script = TRUE;2025 class->process[PROCESS_MAIN]->script = TRUE;
20022026
2003 job = job_new (class, "");2027 job = job_new (class, "");
@@ -2043,6 +2067,7 @@
2043 fclose (output);2067 fclose (output);
20442068
2045 TEST_EQ (unlink (filename), 0);2069 TEST_EQ (unlink (filename), 0);
2070 TEST_EQ (unlink (fifoname), 0);
2046 nih_free (class);2071 nih_free (class);
20472072
2048 /************************************************************/2073 /************************************************************/
@@ -2055,7 +2080,7 @@
2055 */2080 */
20562081
2057 /************************************************************/2082 /************************************************************/
2058 TEST_FEATURE ("with multi-line script that writes 1 byte and is killed");2083 TEST_FEATURE ("with multi-line script that writes 1 byte");
2059 TEST_HASH_EMPTY (job_classes);2084 TEST_HASH_EMPTY (job_classes);
20602085
2061 class = job_class_new (NULL, "multiline", NULL);2086 class = job_class_new (NULL, "multiline", NULL);
@@ -2588,7 +2613,7 @@
2588 class->process[PROCESS_MAIN]->command = nih_sprintf (2613 class->process[PROCESS_MAIN]->command = nih_sprintf (
2589 class->process[PROCESS_MAIN],2614 class->process[PROCESS_MAIN],
2590 "%s if=/dev/zero of=/dev/null bs=1 count=0", TEST_CMD_DD);2615 "%s if=/dev/zero of=/dev/null bs=1 count=0", TEST_CMD_DD);
2591 class->process[PROCESS_MAIN]->script = TRUE;2616 class->process[PROCESS_MAIN]->script = FALSE;
25922617
2593 job = job_new (class, "");2618 job = job_new (class, "");
2594 job->goal = JOB_START;2619 job->goal = JOB_START;

Subscribers

People subscribed via source and target branches