2017-12-12 19:34:17 +00:00
|
|
|
// Flags: --expose-internals
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
|
|
|
const http2 = require('http2');
|
2022-05-24 11:29:56 +00:00
|
|
|
const assert = require('assert');
|
2017-12-12 19:34:17 +00:00
|
|
|
const { kSocket } = require('internal/http2/util');
|
2022-05-24 11:29:56 +00:00
|
|
|
const { ServerHttp2Session } = require('internal/http2/core');
|
2017-12-12 19:34:17 +00:00
|
|
|
|
|
|
|
const server = http2.createServer();
|
|
|
|
server.on('stream', common.mustNotCall());
|
|
|
|
|
|
|
|
let test = 0;
|
|
|
|
|
|
|
|
server.on('session', common.mustCall((session) => {
|
2022-05-24 11:29:56 +00:00
|
|
|
assert.strictEqual(session instanceof ServerHttp2Session, true);
|
2017-12-12 19:34:17 +00:00
|
|
|
switch (++test) {
|
|
|
|
case 1:
|
|
|
|
server.on('error', common.mustNotCall());
|
|
|
|
session.on('error', common.expectsError({
|
2019-12-25 17:02:16 +00:00
|
|
|
name: 'Error',
|
2017-12-12 19:34:17 +00:00
|
|
|
message: 'test'
|
|
|
|
}));
|
|
|
|
session[kSocket].emit('error', new Error('test'));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
// If the server does not have a socketError listener,
|
|
|
|
// error will be silent on the server but will close
|
|
|
|
// the session
|
|
|
|
session[kSocket].emit('error', new Error('test'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}, 2));
|
|
|
|
|
2022-05-24 11:29:56 +00:00
|
|
|
server.on('sessionError', common.mustCall((err, session) => {
|
|
|
|
assert.strictEqual(err.name, 'Error');
|
|
|
|
assert.strictEqual(err.message, 'test');
|
|
|
|
assert.strictEqual(session instanceof ServerHttp2Session, true);
|
|
|
|
}, 2));
|
|
|
|
|
2017-12-12 19:34:17 +00:00
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const url = `http://localhost:${server.address().port}`;
|
|
|
|
http2.connect(url)
|
2022-10-26 09:16:00 +00:00
|
|
|
.on('error', common.mustCall((err) => {
|
|
|
|
if (err.code !== 'ECONNRESET') {
|
|
|
|
assert.strictEqual(err.code, 'ERR_HTTP2_SESSION_ERROR');
|
|
|
|
assert.strictEqual(err.message, 'Session closed with error code 2');
|
|
|
|
}
|
2018-05-17 19:03:15 +00:00
|
|
|
}))
|
2017-12-12 19:34:17 +00:00
|
|
|
.on('close', () => {
|
|
|
|
server.removeAllListeners('error');
|
|
|
|
http2.connect(url)
|
2022-10-26 09:16:00 +00:00
|
|
|
.on('error', common.mustCall((err) => {
|
|
|
|
if (err.code !== 'ECONNRESET') {
|
|
|
|
assert.strictEqual(err.code, 'ERR_HTTP2_SESSION_ERROR');
|
|
|
|
assert.strictEqual(err.message, 'Session closed with error code 2');
|
|
|
|
}
|
|
|
|
}))
|
2017-12-12 19:34:17 +00:00
|
|
|
.on('close', () => server.close());
|
|
|
|
});
|
|
|
|
}));
|