Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: refactor test-http2-buffersize
Remove seemlingly misplaced and/or extraneous comment. Replace countdown
with Promise.all.

PR-URL: #32540
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Trott committed Apr 5, 2020
commit c452632d3421d6baf26a61e14c21c922bd18175e
37 changes: 18 additions & 19 deletions test/parallel/test-http2-buffersize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,45 @@ if (!hasCrypto)
skip('missing crypto');
const assert = require('assert');
const { createServer, connect } = require('http2');
const Countdown = require('../common/countdown');
const { once } = require('events');

// This test ensures that `bufferSize` of Http2Session and Http2Stream work
// as expected.
{
const SOCKETS = 2;
const TIMES = 10;
const BUFFER_SIZE = 30;
const kSockets = 2;
const kTimes = 10;
const kBufferSize = 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) => {
const getStream = async () => {
const [ stream ] = await once(server, 'stream');
stream.on('data', mustCall());
stream.on('end', mustCall());
stream.on('close', mustCall());
return once(stream, 'close');
};

stream.on('close', mustCall(() => {
countdown.dec();
}));
}, SOCKETS));
const promises = [...new Array(kSockets)].map(getStream);
Promise.all(promises).then(mustCall(() => {
client.close();
server.close();
}));

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

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

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

for (let i = 0; i < TIMES; i += 1) {
stream.write(Buffer.allocUnsafe(BUFFER_SIZE), mustCall());
const expectedSocketBufferSize = BUFFER_SIZE * (i + 1);
for (let i = 0; i < kTimes; i += 1) {
stream.write(Buffer.allocUnsafe(kBufferSize), mustCall());
const expectedSocketBufferSize = kBufferSize * (i + 1);
assert.strictEqual(stream.bufferSize, expectedSocketBufferSize);
}
stream.end();
Expand Down