Skip to content

Commit

Permalink
test: make test-http2-buffersize more correct
Browse files Browse the repository at this point in the history
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: #31502
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
addaleax committed Jan 27, 2020
1 parent f284290 commit a5d4a39
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions test/parallel/test-http2-buffersize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a5d4a39

Please sign in to comment.