Skip to content

Commit 9114f0f

Browse files
committed
test: make test-cli-node-options more robust
The test launches over 20 processes asynchronously. That may be too many for underpowered machines in CI with limited PID space. Fixes: nodejs#25028
1 parent 7d0e50d commit 9114f0f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

test/parallel/test-cli-node-options.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ if (process.config.variables.node_without_node_options)
66
// Test options specified by env variable.
77

88
const assert = require('assert');
9-
const exec = require('child_process').execFile;
9+
// Don't change this to execFile(). This test launches too many processes for
10+
// underpowered machines in CI with limited PID space to launch them in parallel
11+
// without causing failures.
12+
const { execFileSync } = require('child_process');
1013

1114
const tmpdir = require('../common/tmpdir');
1215
tmpdir.refresh();
@@ -56,7 +59,7 @@ if (common.hasCrypto) {
5659
expect('--abort_on-uncaught_exception', 'B\n');
5760
expect('--max-old-space-size=0', 'B\n');
5861
expect('--stack-trace-limit=100',
59-
/(\s*at f \(\[eval\]:1:\d*\)\r?\n){100}/,
62+
/(\s*at f \(\[eval\]:1:\d+\)\r?\n){100}/,
6063
'(function f() { f(); })();',
6164
true);
6265

@@ -66,18 +69,23 @@ function expect(opt, want, command = 'console.log("B")', wantsError = false) {
6669
cwd: tmpdir.path,
6770
env: Object.assign({}, process.env, { NODE_OPTIONS: opt }),
6871
maxBuffer: 1e6,
72+
stdio: 'pipe',
6973
};
74+
7075
if (typeof want === 'string')
7176
want = new RegExp(want);
72-
exec(process.execPath, argv, opts, common.mustCall((err, stdout, stderr) => {
73-
if (wantsError) {
74-
stdout = stderr;
75-
} else {
76-
assert.ifError(err);
77-
}
78-
if (want.test(stdout)) return;
7977

80-
const o = JSON.stringify(opt);
81-
assert.fail(`For ${o}, failed to find ${want} in: <\n${stdout}\n>`);
82-
}));
78+
let stdout;
79+
try {
80+
stdout = execFileSync(process.execPath, argv, opts);
81+
} catch (e) {
82+
if (!wantsError)
83+
throw e;
84+
stdout = e.output[2].toString();
85+
}
86+
87+
if (want.test(stdout)) return;
88+
89+
const o = JSON.stringify(opt);
90+
assert.fail(`For ${o}, failed to find ${want} in: <\n${stdout}\n>`);
8391
}

0 commit comments

Comments
 (0)