Skip to content

Commit e501ba2

Browse files
Trotttargos
authored andcommitted
test: refactor test-http2-buffersize
Remove seemlingly misplaced and/or extraneous comment. Replace countdown with Promise.all. PR-URL: #32540 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 31b2cbb commit e501ba2

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

test/parallel/test-http2-buffersize.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,45 @@ if (!hasCrypto)
55
skip('missing crypto');
66
const assert = require('assert');
77
const { createServer, connect } = require('http2');
8-
const Countdown = require('../common/countdown');
8+
const { once } = require('events');
99

1010
// This test ensures that `bufferSize` of Http2Session and Http2Stream work
1111
// as expected.
1212
{
13-
const SOCKETS = 2;
14-
const TIMES = 10;
15-
const BUFFER_SIZE = 30;
13+
const kSockets = 2;
14+
const kTimes = 10;
15+
const kBufferSize = 30;
1616
const server = createServer();
1717

1818
let client;
19-
const countdown = new Countdown(SOCKETS, () => {
20-
client.close();
21-
server.close();
22-
});
2319

24-
// Other `bufferSize` tests for net module and tls module
25-
// don't assert `bufferSize` of server-side sockets.
26-
server.on('stream', mustCall((stream) => {
20+
const getStream = async () => {
21+
const [ stream ] = await once(server, 'stream');
2722
stream.on('data', mustCall());
2823
stream.on('end', mustCall());
24+
stream.on('close', mustCall());
25+
return once(stream, 'close');
26+
};
2927

30-
stream.on('close', mustCall(() => {
31-
countdown.dec();
32-
}));
33-
}, SOCKETS));
28+
const promises = [...new Array(kSockets)].map(getStream);
29+
Promise.all(promises).then(mustCall(() => {
30+
client.close();
31+
server.close();
32+
}));
3433

3534
server.listen(0, mustCall(() => {
3635
const authority = `http://localhost:${server.address().port}`;
3736
client = connect(authority);
3837

3938
client.once('connect', mustCall());
4039

41-
for (let j = 0; j < SOCKETS; j += 1) {
40+
for (let j = 0; j < kSockets; j += 1) {
4241
const stream = client.request({ ':method': 'POST' });
4342
stream.on('data', () => {});
4443

45-
for (let i = 0; i < TIMES; i += 1) {
46-
stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall());
47-
const expectedSocketBufferSize = BUFFER_SIZE * (i + 1);
44+
for (let i = 0; i < kTimes; i += 1) {
45+
stream.write(Buffer.allocUnsafe(kBufferSize), mustCall());
46+
const expectedSocketBufferSize = kBufferSize * (i + 1);
4847
assert.strictEqual(stream.bufferSize, expectedSocketBufferSize);
4948
}
5049
stream.end();

0 commit comments

Comments
 (0)