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 <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
addaleax authored and codebytere committed Feb 17, 2020
1 parent 8669ecc commit 07525c3
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 07525c3

Please sign in to comment.