summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Gilli <julien.gilli@joyent.com>2015-02-27 15:48:34 -0800
committerJulien Gilli <julien.gilli@joyent.com>2015-03-03 14:35:36 -0800
commitd9a309f718d738eb817195118f4daa06fb6f68ee (patch)
treee9e18eac52808cd3edd9751386e7e82e0a24e7ef
parente82e86b1a7fc3e3d15daeb5845f0ce4d83e15e92 (diff)
downloadnode-d9a309f718d738eb817195118f4daa06fb6f68ee.tar.gz
tests: fix race in test-http-curl-chunk-problem
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: #9301 PR-URL: https://github.com/joyent/node/pull/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>
-rw-r--r--test/simple/test-http-curl-chunk-problem.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/test/simple/test-http-curl-chunk-problem.js b/test/simple/test-http-curl-chunk-problem.js
index 701624633..8f6824430 100644
--- a/test/simple/test-http-curl-chunk-problem.js
+++ b/test/simple/test-http-curl-chunk-problem.js
@@ -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();
});
});