node/test/parallel/test-http2-propagate-session-destroy-code.js
Michaël Zasso 508890d795
test: use assert.match instead of regexp.test
PR-URL: https://github.com/nodejs/node/pull/39928
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
2021-08-31 18:50:16 +02:00

55 lines
1.6 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
const errRegEx = /Session closed with error code 7/;
const destroyCode = http2.constants.NGHTTP2_REFUSED_STREAM;
server.on('error', common.mustNotCall());
server.on('session', (session) => {
session.on('close', common.mustCall());
session.on('error', common.mustCall((err) => {
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
}));
session.on('stream', common.mustCall((stream) => {
stream.on('error', common.mustCall((err) => {
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
assert.strictEqual(stream.rstCode, destroyCode);
}));
session.destroy(destroyCode);
}));
});
server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
session.on('error', common.mustCall((err) => {
assert.match(err.message, errRegEx);
assert.strictEqual(session.closed, false);
assert.strictEqual(session.destroyed, true);
}));
const stream = session.request({ [http2.constants.HTTP2_HEADER_PATH]: '/' });
stream.on('error', common.mustCall((err) => {
assert.match(err.message, errRegEx);
assert.strictEqual(stream.rstCode, destroyCode);
}));
stream.on('close', common.mustCall(() => {
server.close();
}));
}));