Merge lp:~xnox/upstart/fix-qemu-test into lp:upstart

Proposed by Dimitri John Ledkov
Status: Superseded
Proposed branch: lp:~xnox/upstart/fix-qemu-test
Merge into: lp:upstart
Diff against target: 24 lines (+10/-0)
1 file modified
init/tests/test_job_process.c (+10/-0)
To merge this branch: bzr merge lp:~xnox/upstart/fix-qemu-test
Reviewer Review Type Date Requested Status
James Hunt Approve
Review via email: mp+137223@code.launchpad.net

This proposal has been superseded by a proposal from 2012-12-03.

Description of the change

Originally the race was noticed in the Ubuntu Cloud image booted in qemu as part of autopkgtest runner.

Waiting for the pid of the test job, makes this race evident on my local host as well.

At first, I have tried to do the log checks in the pid greater than zero branch, but at that time the log was not written yet, hence I moved it later @ the test clean up. I am not sure how correct this is.

With this change & stgrabers initctl2dot merge fix, the autopkgtest pass as run in the jenkins environment.

To post a comment you must log in.
Revision history for this message
James Hunt (jamesodhunt) wrote :

Hi Dmitrijs,

I think this is still subtly racy since it is possible that even in a failure scenario a partial log could be written.

The fix I'd suggest is:

(1) Put a check immediately after the 'nih_free (class)' in the TEST_ALLOC_SAFE block that performs the following checks:

- if test_alloc_failed is true, and the log file exists, just unlink it (there is no point in checking it as it might be only a partial log - we cannot know).

- if test_alloc_failed is not true, ensure the log file exists, check its contents and unlink it (essentially the block you have added).

(2) Re-instate the original 'assert0 (rmdir (dirname))' at the end of the test.

This way, there is no possibility of:

- the tests failing to detect that a full log was somehow written in a failure scenario.
- a failure resulting from a partial log being written in one of the failure iterations, followed by a successful write in the successful iteration (recall that the logs are appended to).

review: Needs Fixing
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Ok, I'll try that. Thanks.

lp:~xnox/upstart/fix-qemu-test updated
1393. By James Hunt

* Merge of lp:~xnox/upstart/fix-qemu-test.

Revision history for this message
James Hunt (jamesodhunt) wrote :

Thanks Dmitrijs! Merged.

review: Approve
lp:~xnox/upstart/fix-qemu-test updated
1394. By Dimitri John Ledkov

Fix the failed code-path

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'init/tests/test_job_process.c'
2--- init/tests/test_job_process.c 2012-11-26 14:04:27 +0000
3+++ init/tests/test_job_process.c 2012-12-03 09:43:23 +0000
4@@ -4787,11 +4787,21 @@
5 assert0 (unlink (script));
6 } else {
7 TEST_GT (pid, 0);
8+ TEST_EQ (waitpid (pid, &status, 0), pid);
9 }
10
11 TEST_ALLOC_SAFE {
12 /* May alloc space if there is log data */
13 nih_free (class);
14+ if (!test_alloc_failed) {
15+ TEST_GT (sprintf (filename, "%s/simple-test.log", dirname), 0);
16+ output = fopen (filename, "r");
17+ TEST_NE_P (output, NULL);
18+ CHECK_FILE_EQ (output, "hello world\r\n", TRUE);
19+ TEST_FILE_END (output);
20+ TEST_EQ (fclose (output), 0);
21+ }
22+ unlink (filename);
23 }
24 }
25

Subscribers

People subscribed via source and target branches