1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5const http2 = require('http2'); 6const EventEmitter = require('events'); 7 8// This test ensures that a MaxListenersExceededWarning isn't emitted if 9// more than EventEmitter.defaultMaxListeners requests are started on a 10// ClientHttp2Session before it has finished connecting. 11 12process.on('warning', common.mustNotCall('A warning was emitted')); 13 14const server = http2.createServer(); 15server.on('stream', (stream) => { 16 stream.respond(); 17 stream.end(); 18}); 19 20server.listen(common.mustCall(() => { 21 const client = http2.connect(`http://localhost:${server.address().port}`); 22 23 function request() { 24 return new Promise((resolve, reject) => { 25 const stream = client.request(); 26 stream.on('error', reject); 27 stream.on('response', resolve); 28 stream.end(); 29 }); 30 } 31 32 const requests = []; 33 for (let i = 0; i < EventEmitter.defaultMaxListeners + 1; i++) { 34 requests.push(request()); 35 } 36 37 Promise.all(requests).then(common.mustCall()).finally(common.mustCall(() => { 38 server.close(); 39 client.close(); 40 })); 41})); 42