11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 81cb0ef41Sopenharmony_ciconst http2 = require('http2'); 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci// Test that the maxConcurrentStreams setting is strictly enforced 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst server = http2.createServer({ settings: { maxConcurrentStreams: 1 } }); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cilet c = 0; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciserver.on('stream', common.mustCall((stream) => { 181cb0ef41Sopenharmony_ci // Because we only allow one open stream at a time, 191cb0ef41Sopenharmony_ci // c should never be greater than 1. 201cb0ef41Sopenharmony_ci assert.strictEqual(++c, 1); 211cb0ef41Sopenharmony_ci stream.respond(); 221cb0ef41Sopenharmony_ci // Force some asynchronous stuff. 231cb0ef41Sopenharmony_ci setImmediate(() => { 241cb0ef41Sopenharmony_ci stream.end('ok'); 251cb0ef41Sopenharmony_ci assert.strictEqual(--c, 0); 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci}, 3)); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 301cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci const countdown = new Countdown(3, common.mustCall(() => { 331cb0ef41Sopenharmony_ci server.close(); 341cb0ef41Sopenharmony_ci client.destroy(); 351cb0ef41Sopenharmony_ci })); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci client.on('remoteSettings', common.mustCall(() => { 381cb0ef41Sopenharmony_ci assert.strictEqual(client.remoteSettings.maxConcurrentStreams, 1); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci { 411cb0ef41Sopenharmony_ci const req = client.request(); 421cb0ef41Sopenharmony_ci req.resume(); 431cb0ef41Sopenharmony_ci req.on('close', () => { 441cb0ef41Sopenharmony_ci countdown.dec(); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci setImmediate(() => { 471cb0ef41Sopenharmony_ci const req = client.request(); 481cb0ef41Sopenharmony_ci req.resume(); 491cb0ef41Sopenharmony_ci req.on('close', () => countdown.dec()); 501cb0ef41Sopenharmony_ci }); 511cb0ef41Sopenharmony_ci }); 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci { 551cb0ef41Sopenharmony_ci const req = client.request(); 561cb0ef41Sopenharmony_ci req.resume(); 571cb0ef41Sopenharmony_ci req.on('close', () => countdown.dec()); 581cb0ef41Sopenharmony_ci } 591cb0ef41Sopenharmony_ci })); 601cb0ef41Sopenharmony_ci})); 61