diff --git a/doc/api/test.md b/doc/api/test.md index 323c41cd94b1d2..b8d05060b9bde9 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -333,10 +333,11 @@ changes: properties are supported: * `concurrency` {number|boolean} If a number is provided, then that many tests would run in parallel. - If truthy, on top level, it would run (number of cpu cores - 1) - tests in parallel. + If truthy, when running in `--test` mode, it would run + (number of cpu cores - 1) tests in parallel. For subtests, it will be infinity tests in parallel. - If falsy, on top level & subtest level it would only run one test at a time. + If falsy, when running in `--test` mode & subtest level + it would only run one test at a time. If unspecified, subtests inherit this value from their parent. **Default:** `1`. * `only` {boolean} If truthy, and the test context is configured to run diff --git a/test/message/test_runner_describe_it.js b/test/message/test_runner_describe_it.js index 897c3be9d7356d..156fecddaf6401 100644 --- a/test/message/test_runner_describe_it.js +++ b/test/message/test_runner_describe_it.js @@ -339,47 +339,3 @@ describe('timeouts', () => { setTimeout(done, 10); }); }); - -describe('Concurrency option (boolean) = true ', { concurrency: true }, () => { - const suiteStartDateTime = new Date().getTime(); - const extraBufferTime = 10; - it('should be over by 3 seconds from suite start', async () => { - const duration = 3000; - const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime; - await new Promise((resolve, reject) => { - setTimeout(resolve, duration); - }); - assert.strictEqual(expectedEndDateTime > new Date().getTime(), true); - }); - it('should be over by 1 second from suite start', async () => { - const duration = 1000; - const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime; - await new Promise((resolve, reject) => { - setTimeout(resolve, duration); - }); - assert.strictEqual(expectedEndDateTime > new Date().getTime(), true); - }); -}); - -describe('Concurrency option (boolean) = false ', { concurrency: false }, () => { - const suiteStartDateTime = new Date().getTime(); - const extraBufferTime = 10; - it('should be over by 3 seconds from suite start', async () => { - const duration = 3000; - const expectedEndDateTime = suiteStartDateTime + duration + extraBufferTime; - await new Promise((resolve, reject) => { - setTimeout(resolve, duration); - }); - assert.strictEqual(expectedEndDateTime > new Date().getTime(), true); - }); - it('should be over by 4 seconds from suite start', async () => { - const duration = 1000; - const prevTestDuration = 3000; - const expectedEndDateTime = - suiteStartDateTime + duration + extraBufferTime + prevTestDuration; - await new Promise((resolve, reject) => { - setTimeout(resolve, duration); - }); - assert.strictEqual(expectedEndDateTime > new Date().getTime(), true); - }); -}); diff --git a/test/parallel/test-runner-concurrency.js b/test/parallel/test-runner-concurrency.js new file mode 100644 index 00000000000000..8d18cee47c9063 --- /dev/null +++ b/test/parallel/test-runner-concurrency.js @@ -0,0 +1,28 @@ +'use strict'; +require('../common'); +const { describe, it } = require('node:test'); +const assert = require('assert'); + +describe('Concurrency option (boolean) = true ', { concurrency: true }, () => { + let isFirstTestOver = false; + it('should end after 1000ms', () => new Promise((resolve) => { + setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000); + })); + it('should start before the previous test ends', () => { + assert.strictEqual(isFirstTestOver, false); + }); +}); + +describe( + 'Concurrency option (boolean) = false ', + { concurrency: false }, + () => { + let isFirstTestOver = false; + it('should end after 1000ms', () => new Promise((resolve) => { + setTimeout(() => { resolve(); isFirstTestOver = true; }, 1000); + })); + it('should start after the previous test ends', () => { + assert.strictEqual(isFirstTestOver, true); + }); + } +);