Skip to content

Commit baa14c9

Browse files
addaleaxcodebytere
authored andcommitted
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: #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]>
1 parent 3d8e850 commit baa14c9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

test/parallel/test-http2-buffersize.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,32 @@ const Countdown = require('../common/countdown');
1515
const BUFFER_SIZE = 30;
1616
const server = createServer();
1717

18+
let client;
19+
const countdown = new Countdown(SOCKETS, () => {
20+
client.close();
21+
server.close();
22+
});
23+
1824
// Other `bufferSize` tests for net module and tls module
1925
// don't assert `bufferSize` of server-side sockets.
2026
server.on('stream', mustCall((stream) => {
2127
stream.on('data', mustCall());
2228
stream.on('end', mustCall());
29+
30+
stream.on('close', mustCall(() => {
31+
countdown.dec();
32+
}));
2333
}, SOCKETS));
2434

2535
server.listen(0, mustCall(() => {
2636
const authority = `http://localhost:${server.address().port}`;
27-
const client = connect(authority);
28-
const countdown = new Countdown(SOCKETS, () => {
29-
client.close();
30-
server.close();
31-
});
37+
client = connect(authority);
3238

3339
client.once('connect', mustCall());
3440

3541
for (let j = 0; j < SOCKETS; j += 1) {
3642
const stream = client.request({ ':method': 'POST' });
3743
stream.on('data', () => {});
38-
stream.on('close', mustCall(() => {
39-
countdown.dec();
40-
}));
4144

4245
for (let i = 0; i < TIMES; i += 1) {
4346
stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall());

0 commit comments

Comments
 (0)