This completely refactors the `expectsError` behavior: so far it's almost identical to `assert.throws(fn, object)` in case it was used with a function as first argument. It had a magical property check that allowed to verify a functions `type` in case `type` was passed used in the validation object. This pattern is now completely removed and `assert.throws()` should be used instead. The main intent for `common.expectsError()` is to verify error cases for callback based APIs. This is now more flexible by accepting all validation possibilites that `assert.throws()` accepts as well. No magical properties exist anymore. This reduces surprising behavior for developers who are not used to the Node.js core code base. This has the side effect that `common` is used significantly less frequent. PR-URL: https://github.com/nodejs/node/pull/31092 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
// Tests that attempting to send too many non-acknowledged
|
|
// settings frames will result in an error
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const h2 = require('http2');
|
|
|
|
const maxOutstandingSettings = 2;
|
|
|
|
function doTest(session) {
|
|
session.on('error', common.expectsError({
|
|
code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
|
|
name: 'Error'
|
|
}));
|
|
for (let n = 0; n < maxOutstandingSettings; n++) {
|
|
session.settings({ enablePush: false });
|
|
assert.strictEqual(session.pendingSettingsAck, true);
|
|
}
|
|
}
|
|
|
|
{
|
|
const server = h2.createServer({ maxOutstandingSettings });
|
|
server.on('stream', common.mustNotCall());
|
|
server.once('session', common.mustCall((session) => doTest(session)));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = h2.connect(`http://localhost:${server.address().port}`);
|
|
client.on('error', common.expectsError({
|
|
code: 'ERR_HTTP2_SESSION_ERROR',
|
|
message: 'Session closed with error code 2',
|
|
}));
|
|
client.on('close', common.mustCall(() => server.close()));
|
|
}));
|
|
}
|
|
|
|
{
|
|
const server = h2.createServer();
|
|
server.on('stream', common.mustNotCall());
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = h2.connect(`http://localhost:${server.address().port}`,
|
|
{ maxOutstandingSettings });
|
|
client.on('connect', () => doTest(client));
|
|
client.on('close', () => server.close());
|
|
}));
|
|
}
|