1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const Countdown = require('../common/countdown'); 8const http2 = require('http2'); 9const assert = require('assert'); 10 11// Test that the maxConcurrentStreams setting is strictly enforced 12 13const server = http2.createServer({ settings: { maxConcurrentStreams: 1 } }); 14 15let c = 0; 16 17server.on('stream', common.mustCall((stream) => { 18 // Because we only allow one open stream at a time, 19 // c should never be greater than 1. 20 assert.strictEqual(++c, 1); 21 stream.respond(); 22 // Force some asynchronous stuff. 23 setImmediate(() => { 24 stream.end('ok'); 25 assert.strictEqual(--c, 0); 26 }); 27}, 3)); 28 29server.listen(0, common.mustCall(() => { 30 const client = http2.connect(`http://localhost:${server.address().port}`); 31 32 const countdown = new Countdown(3, common.mustCall(() => { 33 server.close(); 34 client.destroy(); 35 })); 36 37 client.on('remoteSettings', common.mustCall(() => { 38 assert.strictEqual(client.remoteSettings.maxConcurrentStreams, 1); 39 40 { 41 const req = client.request(); 42 req.resume(); 43 req.on('close', () => { 44 countdown.dec(); 45 46 setImmediate(() => { 47 const req = client.request(); 48 req.resume(); 49 req.on('close', () => countdown.dec()); 50 }); 51 }); 52 } 53 54 { 55 const req = client.request(); 56 req.resume(); 57 req.on('close', () => countdown.dec()); 58 } 59 })); 60})); 61