0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http2-too-many-streams.js
Tobias Nießen e890344d18
test: fix spelling in test case comments
PR-URL: https://github.com/nodejs/node/pull/18018
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2018-01-11 16:49:38 +01:00

61 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const Countdown = require('../common/countdown');
const http2 = require('http2');
const assert = require('assert');
// Test that the maxConcurrentStreams setting is strictly enforced
const server = http2.createServer({ settings: { maxConcurrentStreams: 1 } });
let c = 0;
server.on('stream', common.mustCall((stream) => {
// Because we only allow one open stream at a time,
// c should never be greater than 1.
assert.strictEqual(++c, 1);
stream.respond();
// Force some asynchronous stuff.
setImmediate(() => {
stream.end('ok');
assert.strictEqual(--c, 0);
});
}, 3));
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const countdown = new Countdown(3, common.mustCall(() => {
server.close();
client.destroy();
}));
client.on('remoteSettings', common.mustCall(() => {
assert.strictEqual(client.remoteSettings.maxConcurrentStreams, 1);
{
const req = client.request();
req.resume();
req.on('close', () => {
countdown.dec();
setImmediate(() => {
const req = client.request();
req.resume();
req.on('close', () => countdown.dec());
});
});
}
{
const req = client.request();
req.resume();
req.on('close', () => countdown.dec());
}
}));
}));