2018-10-17 00:44:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
2020-09-06 22:27:07 +02:00
|
|
|
const { mustCall, mustSucceed, hasCrypto, skip } = require('../common');
|
2018-10-17 00:44:49 +08:00
|
|
|
if (!hasCrypto)
|
|
|
|
skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { createServer, connect } = require('http2');
|
2021-07-30 15:36:18 +02:00
|
|
|
const Countdown = require('../common/countdown');
|
2018-10-17 00:44:49 +08:00
|
|
|
|
|
|
|
// This test ensures that `bufferSize` of Http2Session and Http2Stream work
|
|
|
|
// as expected.
|
|
|
|
{
|
2020-03-28 17:03:19 -07:00
|
|
|
const kSockets = 2;
|
|
|
|
const kTimes = 10;
|
|
|
|
const kBufferSize = 30;
|
2018-10-17 00:44:49 +08:00
|
|
|
const server = createServer();
|
|
|
|
|
2020-01-25 02:07:12 +01:00
|
|
|
let client;
|
2021-07-30 15:36:18 +02:00
|
|
|
const countdown = new Countdown(kSockets, () => {
|
|
|
|
client.close();
|
|
|
|
server.close();
|
|
|
|
});
|
2020-01-25 02:07:12 +01:00
|
|
|
|
2021-07-30 15:36:18 +02:00
|
|
|
server.on('stream', mustCall((stream) => {
|
2018-10-17 00:44:49 +08:00
|
|
|
stream.on('data', mustCall());
|
|
|
|
stream.on('end', mustCall());
|
2021-07-30 15:36:18 +02:00
|
|
|
stream.on('close', mustCall(() => {
|
|
|
|
countdown.dec();
|
|
|
|
}));
|
|
|
|
}, kSockets));
|
2018-10-17 00:44:49 +08:00
|
|
|
|
|
|
|
server.listen(0, mustCall(() => {
|
|
|
|
const authority = `http://localhost:${server.address().port}`;
|
2020-01-25 02:07:12 +01:00
|
|
|
client = connect(authority);
|
2018-10-17 00:44:49 +08:00
|
|
|
|
|
|
|
client.once('connect', mustCall());
|
|
|
|
|
2020-03-28 17:03:19 -07:00
|
|
|
for (let j = 0; j < kSockets; j += 1) {
|
2018-10-17 00:44:49 +08:00
|
|
|
const stream = client.request({ ':method': 'POST' });
|
|
|
|
stream.on('data', () => {});
|
|
|
|
|
2020-03-28 17:03:19 -07:00
|
|
|
for (let i = 0; i < kTimes; i += 1) {
|
2020-09-06 22:27:07 +02:00
|
|
|
stream.write(Buffer.allocUnsafe(kBufferSize), mustSucceed());
|
2020-03-28 17:03:19 -07:00
|
|
|
const expectedSocketBufferSize = kBufferSize * (i + 1);
|
2018-10-17 00:44:49 +08:00
|
|
|
assert.strictEqual(stream.bufferSize, expectedSocketBufferSize);
|
|
|
|
}
|
|
|
|
stream.end();
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|