Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42f164c

Browse files
tniessendanielleadams
authored andcommittedJul 6, 2023
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 <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 6ebef57 commit 42f164c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed
 

‎doc/api/test.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,8 @@ changes:
785785
properties are supported:
786786
* `concurrency` {number|boolean} If a number is provided,
787787
then that many tests would run in parallel within the application thread.
788-
If `true`, it would run `os.availableParallelism() - 1` tests in parallel.
789-
For subtests, it will be `Infinity` tests in parallel.
790-
If `false`, it would only run one test at a time.
788+
If `true`, all scheduled asynchronous tests run concurrently within the
789+
thread. If `false`, only one test runs at a time.
791790
If unspecified, subtests inherit this value from their parent.
792791
**Default:** `false`.
793792
* `only` {boolean} If truthy, and the test context is configured to run

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

+17
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)
Please sign in to comment.