1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const http2 = require('http2'); 9const Countdown = require('../common/countdown'); 10 11const server = http2.createServer(); 12server.on('stream', (stream) => { 13 stream.respond(); 14 stream.end('ok'); 15}); 16 17server.listen(0, common.mustCall(() => { 18 const client = http2.connect(`http://localhost:${server.address().port}`); 19 const nextID = 2 ** 31 - 1; 20 21 client.on('connect', () => { 22 client.setNextStreamID(nextID); 23 24 assert.strictEqual(client.state.nextStreamID, nextID); 25 26 const countdown = new Countdown(2, () => { 27 server.close(); 28 client.close(); 29 }); 30 31 { 32 // This one will be ok 33 const req = client.request(); 34 assert.strictEqual(req.id, nextID); 35 36 req.on('error', common.mustNotCall()); 37 req.resume(); 38 req.on('end', () => countdown.dec()); 39 } 40 41 { 42 // This one will error because there are no more stream IDs available 43 const req = client.request(); 44 req.on('error', common.expectsError({ 45 code: 'ERR_HTTP2_OUT_OF_STREAMS', 46 name: 'Error', 47 message: 48 'No stream ID is available because maximum stream ID has been reached' 49 })); 50 req.on('error', () => countdown.dec()); 51 } 52 }); 53})); 54