Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc,test: fix concurrency option of test() #47734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,8 @@ changes:
properties are supported:
* `concurrency` {number|boolean} If a number is provided,
then that many tests would run in parallel within the application thread.
If `true`, it would run `os.availableParallelism() - 1` tests in parallel.
For subtests, it will be `Infinity` tests in parallel.
If `false`, it would only run one test at a time.
If `true`, all scheduled asynchronous tests run concurrently within the
thread. If `false`, only one test runs at a time.
If unspecified, subtests inherit this value from their parent.
**Default:** `false`.
* `only` {boolean} If truthy, and the test context is configured to run
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-runner-concurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const assert = require('node:assert');
const path = require('node:path');
const fs = require('node:fs/promises');
const os = require('node:os');
const timers = require('node:timers/promises');

tmpdir.refresh();

Expand Down Expand Up @@ -35,6 +36,22 @@ describe(
}
);

// Despite the docs saying so at some point, setting concurrency to true should
// not limit concurrency to the number of available CPU cores.
describe('concurrency: true implies Infinity', { concurrency: true }, () => {
// The factor 5 is intentionally chosen to be higher than the default libuv
// thread pool size.
const nTests = 5 * os.availableParallelism();
let nStarted = 0;
for (let i = 0; i < nTests; i++) {
it(`should run test ${i} concurrently`, async () => {
assert.strictEqual(nStarted++, i);
await timers.setImmediate();
assert.strictEqual(nStarted, nTests);
});
}
});

{
// Make sure tests run in order when root concurrency is 1 (default)
const tree = [];
Expand Down