mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
7ece9f3c28
This moves sequential inspector tests that can be run in parallel (using random ports) to parallel. Before: ``` ❯ tools/test.py "test/sequential/test-inspector-*" [00:07|% 100|+ 28|- 0]: Done All tests passed. ❯ tools/test.py "test/parallel/test-inspector-*" [00:01|% 100|+ 26|- 0]: Done All tests passed. ``` After: ``` ❯ tools/test.py "test/sequential/test-inspector-*" [00:00|% 100|+ 1|- 0]: Done All tests passed. ❯ tools/test.py "test/parallel/test-inspector-*" [00:01|% 100|+ 53|- 0]: Done All tests passed. ``` PR-URL: https://github.com/nodejs/node/pull/47412 Refs: https://github.com/nodejs/node/issues/47146 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
'use strict';
|
|
const { mustCall, skipIfInspectorDisabled } = require('../common');
|
|
|
|
skipIfInspectorDisabled();
|
|
|
|
const assert = require('assert');
|
|
const { spawn } = require('child_process');
|
|
|
|
function test(arg, port = '') {
|
|
const args = [arg, '-p', 'process.debugPort'];
|
|
const proc = spawn(process.execPath, args);
|
|
proc.stdout.setEncoding('utf8');
|
|
proc.stderr.setEncoding('utf8');
|
|
let stdout = '';
|
|
let stderr = '';
|
|
proc.stdout.on('data', (data) => stdout += data);
|
|
proc.stderr.on('data', (data) => stderr += data);
|
|
proc.stdout.on('close', (hadErr) => assert(!hadErr));
|
|
proc.stderr.on('close', (hadErr) => assert(!hadErr));
|
|
proc.stderr.on('data', () => {
|
|
if (!stderr.includes('\n')) return;
|
|
assert.match(stderr, /Debugger listening on (.+)/);
|
|
port = new URL(RegExp.$1).port;
|
|
assert(+port > 0);
|
|
});
|
|
if (/inspect-brk/.test(arg)) {
|
|
proc.stderr.on('data', () => {
|
|
if (stderr.includes('\n') && !proc.killed) proc.kill();
|
|
});
|
|
} else {
|
|
let onclose = () => {
|
|
onclose = () => assert.strictEqual(port, stdout.trim());
|
|
};
|
|
proc.stdout.on('close', mustCall(() => onclose()));
|
|
proc.stderr.on('close', mustCall(() => onclose()));
|
|
proc.on('exit', mustCall((exitCode, signal) => assert.strictEqual(
|
|
exitCode,
|
|
0,
|
|
`exitCode: ${exitCode}, signal: ${signal}`)));
|
|
}
|
|
}
|
|
|
|
test('--inspect=0');
|
|
test('--inspect=127.0.0.1:0');
|
|
test('--inspect=localhost:0');
|
|
|
|
test('--inspect-brk=0');
|
|
test('--inspect-brk=127.0.0.1:0');
|
|
test('--inspect-brk=localhost:0');
|
|
|
|
// In these cases, the inspector doesn't listen, so an ephemeral port is not
|
|
// allocated and the expected value of `process.debugPort` is `0`.
|
|
test('--inspect-port=0', '0');
|
|
test('--inspect-port=127.0.0.1:0', '0');
|
|
test('--inspect-port=localhost:0', '0');
|