From 1009130495b4c52d00deed0ee2292039c3f36310 Mon Sep 17 00:00:00 2001 From: Julien Gilli Date: Fri, 27 Feb 2015 15:48:34 -0800 Subject: [PATCH] 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: https://github.com/joyent/node/pull/9301 Reviewed-by: Bert Belder Reviewed-by: Michael Dawson Reviewed-by: Colin Ihrig --- test/parallel/test-http-curl-chunk-problem.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-http-curl-chunk-problem.js b/test/parallel/test-http-curl-chunk-problem.js index 58908fa2d2..fd429c6d5f 100644 --- a/test/parallel/test-http-curl-chunk-problem.js +++ b/test/parallel/test-http-curl-chunk-problem.js @@ -48,13 +48,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(); }); });