11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Tests that attempting to send too many non-acknowledged 41cb0ef41Sopenharmony_ci// settings frames will result in an error 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciif (!common.hasCrypto) 81cb0ef41Sopenharmony_ci common.skip('missing crypto'); 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst h2 = require('http2'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst maxOutstandingSettings = 2; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cifunction doTest(session) { 151cb0ef41Sopenharmony_ci session.on('error', common.expectsError({ 161cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK', 171cb0ef41Sopenharmony_ci name: 'Error' 181cb0ef41Sopenharmony_ci })); 191cb0ef41Sopenharmony_ci for (let n = 0; n < maxOutstandingSettings; n++) { 201cb0ef41Sopenharmony_ci session.settings({ enablePush: false }); 211cb0ef41Sopenharmony_ci assert.strictEqual(session.pendingSettingsAck, true); 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci{ 261cb0ef41Sopenharmony_ci const server = h2.createServer({ maxOutstandingSettings }); 271cb0ef41Sopenharmony_ci server.on('stream', common.mustNotCall()); 281cb0ef41Sopenharmony_ci server.once('session', common.mustCall((session) => doTest(session))); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 311cb0ef41Sopenharmony_ci const client = h2.connect(`http://localhost:${server.address().port}`); 321cb0ef41Sopenharmony_ci client.on('error', common.mustCall((err) => { 331cb0ef41Sopenharmony_ci if (err.code !== 'ECONNRESET') { 341cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ERR_HTTP2_SESSION_ERROR'); 351cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'Session closed with error code 2'); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci })); 381cb0ef41Sopenharmony_ci client.on('close', common.mustCall(() => server.close())); 391cb0ef41Sopenharmony_ci })); 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci{ 431cb0ef41Sopenharmony_ci const server = h2.createServer(); 441cb0ef41Sopenharmony_ci server.on('stream', common.mustNotCall()); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci server.listen(0, common.mustCall(() => { 471cb0ef41Sopenharmony_ci const client = h2.connect(`http://localhost:${server.address().port}`, 481cb0ef41Sopenharmony_ci { maxOutstandingSettings }); 491cb0ef41Sopenharmony_ci client.on('connect', () => doTest(client)); 501cb0ef41Sopenharmony_ci client.on('close', () => server.close()); 511cb0ef41Sopenharmony_ci })); 521cb0ef41Sopenharmony_ci} 53