Skip to content

Commit abdb63d

Browse files
committed
test_runner, cli: add --test-concurrency flag
This commit adds a new --test-concurrency CLI flag that controls the parallelism of the test runner CLI. Fixes: nodejs#49487
1 parent aadfea4 commit abdb63d

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

doc/api/cli.md

+9
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,15 @@ Starts the Node.js command line test runner. This flag cannot be combined with
16511651
See the documentation on [running tests from the command line][]
16521652
for more details.
16531653

1654+
### `--test-concurrency`
1655+
1656+
<!-- YAML
1657+
added: REPLACEME
1658+
-->
1659+
1660+
The maximum number of test files that the test runner CLI will execute
1661+
concurrently. The default value is `os.availableParallelism() - 1`.
1662+
16541663
### `--test-name-pattern`
16551664

16561665
<!-- YAML

doc/api/test.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,12 @@ in the [test runner execution model][] section.
350350

351351
### Test runner execution model
352352

353-
Each matching test file is executed in a separate child process. If the child
354-
process finishes with an exit code of 0, the test is considered passing.
355-
Otherwise, the test is considered to be a failure. Test files must be
356-
executable by Node.js, but are not required to use the `node:test` module
357-
internally.
353+
Each matching test file is executed in a separate child process. The maximum
354+
number of child processes running at any time is controlled by the
355+
[`--test-concurrency`][] flag. If the child process finishes with an exit code
356+
of 0, the test is considered passing. Otherwise, the test is considered to be a
357+
failure. Test files must be executable by Node.js, but are not required to use
358+
the `node:test` module internally.
358359

359360
Each test file is executed as if it was a regular script. That is, if the test
360361
file itself uses `node:test` to define tests, all of those tests will be
@@ -2551,6 +2552,7 @@ added:
25512552
[TTY]: tty.md
25522553
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
25532554
[`--import`]: cli.md#--importmodule
2555+
[`--test-concurrency`]: cli.md#--test-concurrency
25542556
[`--test-name-pattern`]: cli.md#--test-name-pattern
25552557
[`--test-only`]: cli.md#--test-only
25562558
[`--test-reporter-destination`]: cli.md#--test-reporter-destination

doc/node.1

+4
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ Specify the minimum allocation from the OpenSSL secure heap. The default is 2. T
418418
.It Fl -test
419419
Starts the Node.js command line test runner.
420420
.
421+
.It Fl -test-concurrency
422+
The maximum number of test files that the test runner CLI will execute
423+
concurrently.
424+
.
421425
.It Fl -test-name-pattern
422426
A regular expression that configures the test runner to only execute tests
423427
whose name matches the provided pattern.

lib/internal/main/test_runner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const {
2222
prepareMainThreadExecution(false);
2323
markBootstrapComplete();
2424

25-
let concurrency = true;
25+
let concurrency = getOptionValue('--test-concurrency') || true;
2626
let inspectPort;
2727

2828
if (isUsingInspector()) {

src/node_options.cc

+3
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
596596
AddOption("--test",
597597
"launch test runner on startup",
598598
&EnvironmentOptions::test_runner);
599+
AddOption("--test-concurrency",
600+
"specify test runner concurrency",
601+
&EnvironmentOptions::test_runner_concurrency);
599602
AddOption("--experimental-test-coverage",
600603
"enable code coverage in the test runner",
601604
&EnvironmentOptions::test_runner_coverage);

src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class EnvironmentOptions : public Options {
163163
std::string env_file;
164164
bool has_env_file_string = false;
165165
bool test_runner = false;
166+
uint64_t test_runner_concurrency = 0;
166167
bool test_runner_coverage = false;
167168
std::vector<std::string> test_name_pattern;
168169
std::vector<std::string> test_reporter;

0 commit comments

Comments
 (0)