Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Commit

Permalink
tests: fix race in test-http-curl-chunk-problem
Browse files Browse the repository at this point in the history
This test setups two event listeners: one on a child process' exit event
, another for the same child process' stdandard output's 'data' event.
The data even listener writes to a stream, and the exit event listener
ends it.

Because the exit event can be emitted before the data event, there is a
chance that something will be written to the stream after it's ended,
and that an error is thrown.

This change makes the test end the stream in the listener for the child
process' standard output's end event, which is guaranteed to be emitted
after the last data event, thus avoiding the race.

PR: nodejs#9301
PR-URL: nodejs#9301
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@users.noreply.github.com>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
  • Loading branch information
Julien Gilli authored and mhdawson committed Mar 5, 2015
1 parent 9733579 commit 9818e8e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/simple/test-http-curl-chunk-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ var server = http.createServer(function(req, res) {
res.write(data);
});

cat.stdout.on('end', function onStdoutEnd() {
res.end();
});

// End the response on exit (and log errors)
cat.on('exit', function(code) {
if (code !== 0) {
console.error('subprocess exited with code ' + code);
process.exit(1);
}
res.end();
});

});
Expand Down

0 comments on commit 9818e8e

Please sign in to comment.