Skip to content

Commit

Permalink
test_runner: use exiting option instead of cli
Browse files Browse the repository at this point in the history
  • Loading branch information
98lenvi committed Jul 18, 2022
1 parent ae30359 commit 80c40f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
8 changes: 0 additions & 8 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1108,14 +1108,6 @@ 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 tests to run concurrently.

### `--test-only`

<!-- YAML
Expand Down
24 changes: 11 additions & 13 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
'use strict';
const {
ArrayPrototypePush,
ArrayPrototypeReduce,
ArrayPrototypeShift,
ArrayPrototypeUnshift,
FunctionPrototype,
Number,
PromiseResolve,
ReflectApply,
SafeMap,
PromiseRace,
SafePromiseAll,
MathMax
} = primordials;
const { AsyncResource } = require('async_hooks');
const {
Expand Down Expand Up @@ -43,9 +42,7 @@ const noop = FunctionPrototype;
const isTestRunner = getOptionValue('--test');
const testOnlyFlag = !isTestRunner && getOptionValue('--test-only');
// TODO(cjihrig): Use uv_available_parallelism() once it lands.
const isConcurrent = getOptionValue('--test-concurrency');
const rootConcurrency = isTestRunner && isConcurrent ? cpus().length - 1 : 1;
const subTestConcurrency = isConcurrent;
const rootConcurrency = isTestRunner ? MathMax(cpus().length - 1, 1) : 1;

function testTimeout(promise, timeout) {
if (timeout === kDefaultTimeout) {
Expand Down Expand Up @@ -139,6 +136,14 @@ class Test extends AsyncResource {
this.concurrency = concurrency;
}

if (typeof concurrency === 'boolean') {
if (isTestRunner) {
this.concurrency = concurrency ? MathMax(cpus().length - 1, 1) : 1;
} else {
this.concurrency = concurrency ? Infinity : 1;
}
}

if (isUint32(timeout)) {
this.timeout = timeout;
}
Expand Down Expand Up @@ -508,14 +513,7 @@ class Suite extends Test {
this.parent.activeSubtests++;
this.startTime = hrtime();
const subtests = this.skipped || this.error ? [] : this.subtests;
if (subTestConcurrency) {
await SafePromiseAll(subtests, (subtests) => subtests.start());
} else {
await testTimeout(ArrayPrototypeReduce(subtests, async (prev, subtest) => {
await prev;
await subtest.run();
}, PromiseResolve()), this.timeout);
}
await SafePromiseAll(subtests, (subtests) => subtests.start());
this.pass();
this.postRun();
}
Expand Down
3 changes: 0 additions & 3 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,6 @@ 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: 0 additions & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ 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 80c40f8

Please sign in to comment.