2017-04-09 12:27:19 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2017-08-28 04:31:29 +02:00
|
|
|
const { createServer, get } = require('http');
|
|
|
|
const { spawn } = require('child_process');
|
2017-04-09 12:27:19 +02:00
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
2017-08-28 04:31:29 +02:00
|
|
|
// sub-process
|
|
|
|
const server = createServer(common.mustCall((_, res) => res.end('h')));
|
2018-11-07 05:23:08 +01:00
|
|
|
server.listen(0, common.mustCall(() => {
|
2017-08-28 04:31:29 +02:00
|
|
|
const rr = get({ port: server.address().port }, common.mustCall(() => {
|
|
|
|
// This bad input (0) should abort the parser and the process
|
|
|
|
rr.parser.consume(0);
|
2018-01-06 19:34:27 +01:00
|
|
|
// This line should be unreachable.
|
2017-08-28 04:31:29 +02:00
|
|
|
assert.fail('this should be unreachable');
|
|
|
|
}));
|
2017-04-09 12:27:19 +02:00
|
|
|
}));
|
|
|
|
} else {
|
2018-01-06 19:34:27 +01:00
|
|
|
// super-process
|
2017-08-28 04:31:29 +02:00
|
|
|
const child = spawn(process.execPath, [__filename, 'child']);
|
|
|
|
child.stdout.on('data', common.mustNotCall());
|
|
|
|
|
|
|
|
let stderr = '';
|
|
|
|
child.stderr.on('data', common.mustCallAtLeast((data) => {
|
|
|
|
assert(Buffer.isBuffer(data));
|
|
|
|
stderr += data.toString('utf8');
|
|
|
|
}, 1));
|
2017-04-09 12:27:19 +02:00
|
|
|
child.on('exit', common.mustCall((code, signal) => {
|
2017-08-28 04:31:29 +02:00
|
|
|
assert(stderr.includes('failed'), `stderr: ${stderr}`);
|
|
|
|
const didAbort = common.nodeProcessAborted(code, signal);
|
|
|
|
assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
|
2017-04-09 12:27:19 +02:00
|
|
|
}));
|
|
|
|
}
|