1'use strict';
2const common = require('../common');
3const fixtures = require('../common/fixtures');
4
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7
8const child_process = require('child_process');
9const http2 = require('http2');
10const fs = require('fs');
11
12const key = fixtures.readKey('agent8-key.pem', 'binary');
13const cert = fixtures.readKey('agent8-cert.pem', 'binary');
14
15const server = http2.createSecureServer({ key, cert }, (request, response) => {
16  fs.createReadStream(process.execPath).pipe(response);
17});
18
19// This should be doable with a reproduction purely written in Node;
20// that just requires somebody to take the time and actually do it.
21server.listen(0, () => {
22  const proc = child_process.spawn('h2load', [
23    '-n', '1000',
24    `https://localhost:${server.address().port}/`,
25  ]);
26  proc.on('error', (err) => {
27    if (err.code === 'ENOENT')
28      common.skip('no h2load');
29  });
30  proc.on('exit', () => server.close());
31  setTimeout(() => proc.kill(2), 100);
32});
33