• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const { createServer, get } = require('http');
5const { spawn } = require('child_process');
6
7if (process.argv[2] === 'child') {
8  // sub-process
9  const server = createServer(common.mustCall((_, res) => res.end('h')));
10  server.listen(0, common.mustCall(() => {
11    const rr = get({ port: server.address().port }, common.mustCall(() => {
12      // This bad input (0) should abort the parser and the process
13      rr.parser.consume(0);
14      // This line should be unreachable.
15      assert.fail('this should be unreachable');
16    }));
17  }));
18} else {
19  // super-process
20  const child = spawn(process.execPath, [__filename, 'child']);
21  child.stdout.on('data', common.mustNotCall());
22
23  let stderr = '';
24  child.stderr.on('data', common.mustCallAtLeast((data) => {
25    assert(Buffer.isBuffer(data));
26    stderr += data.toString('utf8');
27  }, 1));
28  child.on('exit', common.mustCall((code, signal) => {
29    assert(stderr.includes('failed'), `stderr: ${stderr}`);
30    const didAbort = common.nodeProcessAborted(code, signal);
31    assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
32  }));
33}
34