From 9d752d52820c43163daac080452dc2f83196191a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 18 Jul 2017 08:45:41 -0700 Subject: [PATCH] test: fix flakiness in test-http2-client-upload Race condition in the closing of the stream causing failure on some platforms. Backport-PR-URL: https://github.com/nodejs/node/pull/14813 Backport-Reviewed-By: Anna Henningsen Backport-Reviewed-By: Timothy Gu PR-URL: https://github.com/nodejs/node/pull/14239 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Matteo Collina --- test/parallel/test-http2-client-upload.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) mode change 100644 => 100755 test/parallel/test-http2-client-upload.js diff --git a/test/parallel/test-http2-client-upload.js b/test/parallel/test-http2-client-upload.js old mode 100644 new mode 100755 index 4ce7da878e1fd2..f65ae09c3a205b --- a/test/parallel/test-http2-client-upload.js +++ b/test/parallel/test-http2-client-upload.js @@ -32,13 +32,21 @@ fs.readFile(loc, common.mustCall((err, data) => { server.listen(0, common.mustCall(() => { const client = http2.connect(`http://localhost:${server.address().port}`); + + let remaining = 2; + function maybeClose() { + if (--remaining === 0) { + server.close(); + client.destroy(); + } + } + const req = client.request({ ':method': 'POST' }); req.on('response', common.mustCall()); req.resume(); - req.on('end', common.mustCall(() => { - server.close(); - client.destroy(); - })); - fs.createReadStream(loc).pipe(req); + req.on('end', common.mustCall(maybeClose)); + const str = fs.createReadStream(loc); + str.on('end', common.mustCall(maybeClose)); + str.pipe(req); })); }));