From 4967bd0c0af4f13ffe0eb248ec2bbed6e815db93 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 25 Jan 2020 02:07:12 +0100 Subject: [PATCH] test: make test-http2-buffersize more correct Previously, this code could have closed the server before the connection was actually received by the server, as the `'close'` event on the client side can be emitted before the connection is established. The following commit exacerbates this problem, so fix the test first. PR-URL: https://github.com/nodejs/node/pull/31502 Reviewed-By: Yongsheng Zhang Reviewed-By: David Carlier Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung --- test/parallel/test-http2-buffersize.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-http2-buffersize.js b/test/parallel/test-http2-buffersize.js index be56d8ce3d9344..f18cc4c1ec4e18 100644 --- a/test/parallel/test-http2-buffersize.js +++ b/test/parallel/test-http2-buffersize.js @@ -15,29 +15,32 @@ const Countdown = require('../common/countdown'); const BUFFER_SIZE = 30; const server = createServer(); + let client; + const countdown = new Countdown(SOCKETS, () => { + client.close(); + server.close(); + }); + // Other `bufferSize` tests for net module and tls module // don't assert `bufferSize` of server-side sockets. server.on('stream', mustCall((stream) => { stream.on('data', mustCall()); stream.on('end', mustCall()); + + stream.on('close', mustCall(() => { + countdown.dec(); + })); }, SOCKETS)); server.listen(0, mustCall(() => { const authority = `http://localhost:${server.address().port}`; - const client = connect(authority); - const countdown = new Countdown(SOCKETS, () => { - client.close(); - server.close(); - }); + client = connect(authority); client.once('connect', mustCall()); for (let j = 0; j < SOCKETS; j += 1) { const stream = client.request({ ':method': 'POST' }); stream.on('data', () => {}); - stream.on('close', mustCall(() => { - countdown.dec(); - })); for (let i = 0; i < TIMES; i += 1) { stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall());