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 assert = require('assert'); 81cb0ef41Sopenharmony_ciconst http2 = require('http2'); 91cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst server = http2.createServer(); 121cb0ef41Sopenharmony_ciserver.on('stream', (stream) => { 131cb0ef41Sopenharmony_ci stream.respond(); 141cb0ef41Sopenharmony_ci stream.end('ok'); 151cb0ef41Sopenharmony_ci}); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 181cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`); 191cb0ef41Sopenharmony_ci const nextID = 2 ** 31 - 1; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci client.on('connect', () => { 221cb0ef41Sopenharmony_ci client.setNextStreamID(nextID); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci assert.strictEqual(client.state.nextStreamID, nextID); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci const countdown = new Countdown(2, () => { 271cb0ef41Sopenharmony_ci server.close(); 281cb0ef41Sopenharmony_ci client.close(); 291cb0ef41Sopenharmony_ci }); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci { 321cb0ef41Sopenharmony_ci // This one will be ok 331cb0ef41Sopenharmony_ci const req = client.request(); 341cb0ef41Sopenharmony_ci assert.strictEqual(req.id, nextID); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci req.on('error', common.mustNotCall()); 371cb0ef41Sopenharmony_ci req.resume(); 381cb0ef41Sopenharmony_ci req.on('end', () => countdown.dec()); 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci { 421cb0ef41Sopenharmony_ci // This one will error because there are no more stream IDs available 431cb0ef41Sopenharmony_ci const req = client.request(); 441cb0ef41Sopenharmony_ci req.on('error', common.expectsError({ 451cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_OUT_OF_STREAMS', 461cb0ef41Sopenharmony_ci name: 'Error', 471cb0ef41Sopenharmony_ci message: 481cb0ef41Sopenharmony_ci 'No stream ID is available because maximum stream ID has been reached' 491cb0ef41Sopenharmony_ci })); 501cb0ef41Sopenharmony_ci req.on('error', () => countdown.dec()); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci }); 531cb0ef41Sopenharmony_ci})); 54