Skip to content

Commit

Permalink
test_runner: introduces test_concurrency flag
Browse files Browse the repository at this point in the history
adds the test_concurrency flag,
if set to true, runs all the tests in parallel

Fixes: nodejs#43837
  • Loading branch information
98lenvi committed Jul 19, 2022
1 parent 8657d6d commit bc6fc52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,14 @@ Starts the Node.js command line test runner. This flag cannot be combined with
`--check`, `--eval`, `--interactive`, or the inspector. See the documentation
on [running tests from the command line][] for more details.

### `--test-concurrency`

<!-- YAML
added: REPLACEME
-->

Configures the test runner to run sub tests in parallel.

### `--test-only`

<!-- YAML
Expand Down
15 changes: 12 additions & 3 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
const {
ArrayPrototypePush,
ArrayPrototypeReduce,
ArrayPrototypeShift,
ArrayPrototypeUnshift,
FunctionPrototype,
Number,
PromiseResolve,
ReflectApply,
SafeMap,
PromiseRace,
Expand Down Expand Up @@ -41,8 +43,8 @@ const noop = FunctionPrototype;
const isTestRunner = getOptionValue('--test');
const testOnlyFlag = !isTestRunner && getOptionValue('--test-only');
// TODO(cjihrig): Use uv_available_parallelism() once it lands.
const rootConcurrency = isTestRunner ? cpus().length : 1;

const rootConcurrency = isTestRunner ? cpus().length - 1 : 1;
const subTestConcurrency = getOptionValue('--test-concurrency');

function testTimeout(promise, timeout) {
if (timeout === kDefaultTimeout) {
Expand Down Expand Up @@ -505,7 +507,14 @@ class Suite extends Test {
this.parent.activeSubtests++;
this.startTime = hrtime();
const subtests = this.skipped || this.error ? [] : this.subtests;
await SafePromiseAll(subtests, (subtests) => subtests.start());
if (subTestConcurrency) {
await SafePromiseAll(subtests, (subtests) => subtests.start());
} else {
await testTimeout(ArrayPrototypeReduce(subtests, async (prev, subtest) => {
await prev;
await subtest.run();
}, PromiseResolve()), this.timeout);
}
this.pass();
this.postRun();
}
Expand Down
3 changes: 3 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption("--test",
"launch test runner on startup",
&EnvironmentOptions::test_runner);
AddOption("--test-concurrency",
"tests defined within a file run in parallel",
&EnvironmentOptions::test_concurrency);
AddOption("--test-only",
"run tests with 'only' option set",
&EnvironmentOptions::test_only,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class EnvironmentOptions : public Options {
std::string redirect_warnings;
std::string diagnostic_dir;
bool test_runner = false;
bool test_concurrency = false;
bool test_only = false;
bool test_udp_no_try_send = false;
bool throw_deprecation = false;
Expand Down

0 comments on commit bc6fc52

Please sign in to comment.