node/test/parallel/test-http2-no-more-streams.js
James M Snell 0babd181a0 http2: cleanup Http2Stream/Http2Session destroy
PR-URL: https://github.com/nodejs/node/pull/17406
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>

This is a significant cleanup and refactoring of the
cleanup/close/destroy logic for Http2Stream and Http2Session.
There are significant changes here in the timing and ordering
of cleanup logic, JS apis. and various related necessary edits.
2017-12-18 10:19:21 -08:00

54 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const Countdown = require('../common/countdown');
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond();
stream.end('ok');
});
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const nextID = 2 ** 31 - 1;
client.on('connect', () => {
client.setNextStreamID(nextID);
assert.strictEqual(client.state.nextStreamID, nextID);
const countdown = new Countdown(2, common.mustCall(() => {
server.close();
client.close();
}));
{
// This one will be ok
const req = client.request();
assert.strictEqual(req.id, nextID);
req.on('error', common.mustNotCall());
req.resume();
req.on('end', () => countdown.dec());
}
{
// This one will error because there are no more stream IDs available
const req = client.request();
req.on('error', common.expectsError({
code: 'ERR_HTTP2_OUT_OF_STREAMS',
type: Error,
message:
'No stream ID is available because maximum stream ID has been reached'
}));
req.on('error', () => countdown.dec());
}
});
}));