mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
83410d6ac8
PR-URL: https://github.com/nodejs/node/pull/24213 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { createServer, get } = require('http');
|
|
const { spawn } = require('child_process');
|
|
|
|
if (process.argv[2] === 'child') {
|
|
// sub-process
|
|
const server = createServer(common.mustCall((_, res) => res.end('h')));
|
|
server.listen(0, common.mustCall(() => {
|
|
const rr = get({ port: server.address().port }, common.mustCall(() => {
|
|
// This bad input (0) should abort the parser and the process
|
|
rr.parser.consume(0);
|
|
// This line should be unreachable.
|
|
assert.fail('this should be unreachable');
|
|
}));
|
|
}));
|
|
} else {
|
|
// super-process
|
|
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));
|
|
child.on('exit', common.mustCall((code, signal) => {
|
|
assert(stderr.includes('failed'), `stderr: ${stderr}`);
|
|
const didAbort = common.nodeProcessAborted(code, signal);
|
|
assert(didAbort, `process did not abort, code:${code} signal:${signal}`);
|
|
}));
|
|
}
|