Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 185d609

Browse filesBrowse files
tniessentargos
authored andcommitted
doc,test: fix concurrency option of test()
The documentation appears to still be wrong w.r.t. the meaning of the concurrency option of the test() function. The implementation appears to default to Infinity when the option is set to true. Is that intended or a good idea? I don't know. It certainly makes more sense than what the documentation says (which is basing the number of concurrent tasks within a single thread on the number of CPU cores). This changes the documentation to hopefully match the implementation and adds a test that rules out the (rather arbitrary) behavior described in the documentation. Refs: #47365 Refs: #47642 PR-URL: #47734 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6ee5e42 commit 185d609
Copy full SHA for 185d609

File tree

Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-3
lines changed
Open diff view settings
Collapse file

‎doc/api/test.md‎

Copy file name to clipboardExpand all lines: doc/api/test.md
+2-3Lines changed: 2 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,8 @@ changes:
808808
properties are supported:
809809
* `concurrency` {number|boolean} If a number is provided,
810810
then that many tests would run in parallel within the application thread.
811-
If `true`, it would run `os.availableParallelism() - 1` tests in parallel.
812-
For subtests, it will be `Infinity` tests in parallel.
813-
If `false`, it would only run one test at a time.
811+
If `true`, all scheduled asynchronous tests run concurrently within the
812+
thread. If `false`, only one test runs at a time.
814813
If unspecified, subtests inherit this value from their parent.
815814
**Default:** `false`.
816815
* `only` {boolean} If truthy, and the test context is configured to run
Collapse file

‎test/parallel/test-runner-concurrency.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-runner-concurrency.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const assert = require('node:assert');
77
const path = require('node:path');
88
const fs = require('node:fs/promises');
99
const os = require('node:os');
10+
const timers = require('node:timers/promises');
1011

1112
tmpdir.refresh();
1213

@@ -35,6 +36,22 @@ describe(
3536
}
3637
);
3738

39+
// Despite the docs saying so at some point, setting concurrency to true should
40+
// not limit concurrency to the number of available CPU cores.
41+
describe('concurrency: true implies Infinity', { concurrency: true }, () => {
42+
// The factor 5 is intentionally chosen to be higher than the default libuv
43+
// thread pool size.
44+
const nTests = 5 * os.availableParallelism();
45+
let nStarted = 0;
46+
for (let i = 0; i < nTests; i++) {
47+
it(`should run test ${i} concurrently`, async () => {
48+
assert.strictEqual(nStarted++, i);
49+
await timers.setImmediate();
50+
assert.strictEqual(nStarted, nTests);
51+
});
52+
}
53+
});
54+
3855
{
3956
// Make sure tests run in order when root concurrency is 1 (default)
4057
const tree = [];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.