Skip to content

Commit 7746771

Browse files
committed
test_runner: introduces test_concurrency flag
adds the test_concurrency flag, if set to true, runs all the tests in parallel Fixes: nodejs#43837
1 parent dd167ff commit 7746771

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

doc/api/cli.md

+8
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,14 @@ Starts the Node.js command line test runner. This flag cannot be combined with
11081108
`--check`, `--eval`, `--interactive`, or the inspector. See the documentation
11091109
on [running tests from the command line][] for more details.
11101110

1111+
### `--test-concurrency`
1112+
1113+
<!-- YAML
1114+
added: REPLACEME
1115+
-->
1116+
1117+
Configures the test runner to run sub tests in parallel.
1118+
11111119
### `--test-only`
11121120

11131121
<!-- YAML

lib/internal/test_runner/test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22
const {
33
ArrayPrototypePush,
4+
ArrayPrototypeReduce,
45
ArrayPrototypeShift,
56
ArrayPrototypeUnshift,
67
FunctionPrototype,
78
Number,
9+
PromiseResolve,
810
ReflectApply,
911
SafeMap,
1012
PromiseRace,
@@ -41,8 +43,8 @@ const noop = FunctionPrototype;
4143
const isTestRunner = getOptionValue('--test');
4244
const testOnlyFlag = !isTestRunner && getOptionValue('--test-only');
4345
// TODO(cjihrig): Use uv_available_parallelism() once it lands.
44-
const rootConcurrency = isTestRunner ? cpus().length : 1;
45-
46+
const rootConcurrency = isTestRunner ? cpus().length - 1 : 1;
47+
const subTestConcurrency = getOptionValue('--test-concurrency');
4648

4749
function testTimeout(promise, timeout) {
4850
if (timeout === kDefaultTimeout) {
@@ -505,7 +507,14 @@ class Suite extends Test {
505507
this.parent.activeSubtests++;
506508
this.startTime = hrtime();
507509
const subtests = this.skipped || this.error ? [] : this.subtests;
508-
await SafePromiseAll(subtests, (subtests) => subtests.start());
510+
if (subTestConcurrency) {
511+
await SafePromiseAll(subtests, (subtests) => subtests.start());
512+
} else {
513+
await testTimeout(ArrayPrototypeReduce(subtests, async (prev, subtest) => {
514+
await prev;
515+
await subtest.run();
516+
}, PromiseResolve()), this.timeout);
517+
}
509518
this.pass();
510519
this.postRun();
511520
}

src/node_options.cc

+3
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
525525
AddOption("--test",
526526
"launch test runner on startup",
527527
&EnvironmentOptions::test_runner);
528+
AddOption("--test-concurrency",
529+
"tests defined within a file run in parallel",
530+
&EnvironmentOptions::test_concurrency);
528531
AddOption("--test-only",
529532
"run tests with 'only' option set",
530533
&EnvironmentOptions::test_only,

src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class EnvironmentOptions : public Options {
150150
std::string redirect_warnings;
151151
std::string diagnostic_dir;
152152
bool test_runner = false;
153+
bool test_concurrency = false;
153154
bool test_only = false;
154155
bool test_udp_no_try_send = false;
155156
bool throw_deprecation = false;

0 commit comments

Comments
 (0)