GeezerVison is showing github.com — test_runner, cli: add --test-concurrency flag · nodejs/node@709c6c0
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +9Lines changed: 9 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1626,6 +1626,15 @@ Starts the Node.js command line test runner. This flag cannot be combined with | 1626 | 1626 | See the documentation on [running tests from the command line][] | 1627 | 1627 | for more details. | 1628 | 1628 |
| | 1629 | +### `--test-concurrency` | | 1630 | + | | 1631 | +<!-- YAML | | 1632 | +added: REPLACEME | | 1633 | +--> | | 1634 | + | | 1635 | +The maximum number of test files that the test runner CLI will execute | | 1636 | +concurrently. The default value is `os.availableParallelism() - 1`. | | 1637 | + | 1629 | 1638 | ### `--test-name-pattern` | 1630 | 1639 |
| 1631 | 1640 | <!-- YAML | |
Collapse file Copy file name to clipboardExpand all lines: doc/api/test.md +7-5Lines changed: 7 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -373,11 +373,12 @@ When searching for test files to execute, the test runner behaves as follows: | 373 | 373 | automatically executed by the test runner, but are supported if explicitly | 374 | 374 | provided on the command line. | 375 | 375 |
| 376 | | -Each matching test file is executed in a separate child process. If the child | 377 | | -process finishes with an exit code of 0, the test is considered passing. | 378 | | -Otherwise, the test is considered to be a failure. Test files must be | 379 | | -executable by Node.js, but are not required to use the `node:test` module | 380 | | -internally. | | 376 | +Each matching test file is executed in a separate child process. The maximum | | 377 | +number of child processes running at any time is controlled by the | | 378 | +[`--test-concurrency`][] flag. If the child process finishes with an exit code | | 379 | +of 0, the test is considered passing. Otherwise, the test is considered to be a | | 380 | +failure. Test files must be executable by Node.js, but are not required to use | | 381 | +the `node:test` module internally. | 381 | 382 |
| 382 | 383 | Each test file is executed as if it was a regular script. That is, if the test | 383 | 384 | file itself uses `node:test` to define tests, all of those tests will be | @@ -2562,6 +2563,7 @@ added: | 2562 | 2563 | [TTY]: tty.md | 2563 | 2564 | [`--experimental-test-coverage`]: cli.md#--experimental-test-coverage | 2564 | 2565 | [`--import`]: cli.md#--importmodule | | 2566 | +[`--test-concurrency`]: cli.md#--test-concurrency | 2565 | 2567 | [`--test-name-pattern`]: cli.md#--test-name-pattern | 2566 | 2568 | [`--test-only`]: cli.md#--test-only | 2567 | 2569 | [`--test-reporter-destination`]: cli.md#--test-reporter-destination | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -418,6 +418,10 @@ Specify the minimum allocation from the OpenSSL secure heap. The default is 2. T | 418 | 418 | .It Fl -test | 419 | 419 | Starts the Node.js command line test runner. | 420 | 420 | . | | 421 | +.It Fl -test-concurrency | | 422 | +The maximum number of test files that the test runner CLI will execute | | 423 | +concurrently. | | 424 | +. | 421 | 425 | .It Fl -test-name-pattern | 422 | 426 | A regular expression that configures the test runner to only execute tests | 423 | 427 | whose name matches the provided pattern. | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/test_runner.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ const { | 22 | 22 | prepareMainThreadExecution(false); | 23 | 23 | markBootstrapComplete(); | 24 | 24 |
| 25 | | -let concurrency = true; | | 25 | +let concurrency = getOptionValue('--test-concurrency') || true; | 26 | 26 | let inspectPort; | 27 | 27 |
| 28 | 28 | if (isUsingInspector()) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -595,6 +595,9 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 595 | 595 | AddOption("--test", | 596 | 596 | "launch test runner on startup", | 597 | 597 | &EnvironmentOptions::test_runner); | | 598 | + AddOption("--test-concurrency", | | 599 | + "specify test runner concurrency", | | 600 | + &EnvironmentOptions::test_runner_concurrency); | 598 | 601 | AddOption("--experimental-test-coverage", | 599 | 602 | "enable code coverage in the test runner", | 600 | 603 | &EnvironmentOptions::test_runner_coverage); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -159,6 +159,7 @@ class EnvironmentOptions : public Options { | 159 | 159 | std::string env_file; | 160 | 160 | bool has_env_file_string = false; | 161 | 161 | bool test_runner = false; | | 162 | + uint64_t test_runner_concurrency = 0; | 162 | 163 | bool test_runner_coverage = false; | 163 | 164 | std::vector<std::string> test_name_pattern; | 164 | 165 | std::vector<std::string> test_reporter; | |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | +const tmpdir = require('../common/tmpdir'); | | 4 | +const { deepStrictEqual, strictEqual } = require('node:assert'); | | 5 | +const { spawnSync } = require('node:child_process'); | | 6 | +const { readdirSync, writeFileSync } = require('node:fs'); | | 7 | +const { join } = require('node:path'); | | 8 | +const { beforeEach, test } = require('node:test'); | | 9 | + | | 10 | +function createTestFile(name) { | | 11 | + writeFileSync(join(tmpdir.path, name), ` | | 12 | + const fs = require('node:fs'); | | 13 | +
| | 14 | + fs.unlinkSync(__filename); | | 15 | + setTimeout(() => {}, 1_000_000_000); | | 16 | + `); | | 17 | +} | | 18 | + | | 19 | +beforeEach(() => { | | 20 | + tmpdir.refresh(); | | 21 | + createTestFile('test-1.js'); | | 22 | + createTestFile('test-2.js'); | | 23 | +}); | | 24 | + | | 25 | +test('concurrency of one', () => { | | 26 | + const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], { | | 27 | + cwd: tmpdir.path, | | 28 | + timeout: common.platformTimeout(1000), | | 29 | + }); | | 30 | + | | 31 | + strictEqual(cp.stderr.toString(), ''); | | 32 | + strictEqual(cp.error.code, 'ETIMEDOUT'); | | 33 | + deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']); | | 34 | +}); | | 35 | + | | 36 | +test('concurrency of two', () => { | | 37 | + const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], { | | 38 | + cwd: tmpdir.path, | | 39 | + timeout: common.platformTimeout(1000), | | 40 | + }); | | 41 | + | | 42 | + strictEqual(cp.stderr.toString(), ''); | | 43 | + strictEqual(cp.error.code, 'ETIMEDOUT'); | | 44 | + deepStrictEqual(readdirSync(tmpdir.path), []); | | 45 | +}); |
|