tests: fix race in test-http-curl-chunk-problem
authorJulien Gilli <julien.gilli@joyent.com>
Fri, 27 Feb 2015 23:48:34 +0000 (15:48 -0800)
committerBert Belder <bertbelder@gmail.com>
Tue, 3 Mar 2015 15:00:53 +0000 (16:00 +0100)
commit1009130495b4c52d00deed0ee2292039c3f36310
tree05f957cb2780cd1a80d2088998ebafed4fc6faa1
parent6433ad1eef0613754a97c16a866945b97801963d
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 <bertbelder@gmail.com>
Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
test/parallel/test-http-curl-chunk-problem.js