Skip to content

Commit 07525c3

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 <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>
1 parent 8669ecc commit 07525c3

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎test/parallel/test-http2-buffersize.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,32 @@ const Countdown = require('../common/countdown');
1515
constBUFFER_SIZE=30;
1616
constserver=createServer();
1717

18+
letclient;
19+
constcountdown=newCountdown(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
constauthority=`http://localhost:${server.address().port}`;
27-
constclient=connect(authority);
28-
constcountdown=newCountdown(SOCKETS,()=>{
29-
client.close();
30-
server.close();
31-
});
37+
client=connect(authority);
3238

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

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

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

0 commit comments

Comments
 (0)