11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { createServer, get } = require('http');
51cb0ef41Sopenharmony_ciconst { spawn } = require('child_process');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
81cb0ef41Sopenharmony_ci  // sub-process
91cb0ef41Sopenharmony_ci  const server = createServer(common.mustCall((_, res) => res.end('h')));
101cb0ef41Sopenharmony_ci  server.listen(0, common.mustCall(() => {
111cb0ef41Sopenharmony_ci    const rr = get({ port: server.address().port }, common.mustCall(() => {
121cb0ef41Sopenharmony_ci      // This bad input (0) should abort the parser and the process
131cb0ef41Sopenharmony_ci      rr.parser.consume(0);
141cb0ef41Sopenharmony_ci      // This line should be unreachable.
151cb0ef41Sopenharmony_ci      assert.fail('this should be unreachable');
161cb0ef41Sopenharmony_ci    }));
171cb0ef41Sopenharmony_ci  }));
181cb0ef41Sopenharmony_ci} else {
191cb0ef41Sopenharmony_ci  // super-process
201cb0ef41Sopenharmony_ci  const child = spawn(process.execPath, [__filename, 'child']);
211cb0ef41Sopenharmony_ci  child.stdout.on('data', common.mustNotCall());
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  let stderr = '';
241cb0ef41Sopenharmony_ci  child.stderr.on('data', common.mustCallAtLeast((data) => {
251cb0ef41Sopenharmony_ci    assert(Buffer.isBuffer(data));
261cb0ef41Sopenharmony_ci    stderr += data.toString('utf8');
271cb0ef41Sopenharmony_ci  }, 1));
281cb0ef41Sopenharmony_ci  child.on('exit', common.mustCall((code, signal) => {
291cb0ef41Sopenharmony_ci    assert(stderr.includes('failed'), `stderr: ${stderr}`);
301cb0ef41Sopenharmony_ci    const didAbort = common.nodeProcessAborted(code, signal);
311cb0ef41Sopenharmony_ci    assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
321cb0ef41Sopenharmony_ci  }));
331cb0ef41Sopenharmony_ci}
34