Skip to content

--test-concurrency has no effect on single test file #51186

Description

@hulkish

Version

21.4.0

Platform

Darwin Stevens-MacBook-Pro.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:32:52 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T8122 arm64

Subsystem

No response

What steps will reproduce the bug?

  1. create test file foo.test.mjs:
import { describe, it } from 'node:test';

// when ran with --test-concurrency of anything greater than 1, has no effect, uses concurrency of 1
describe('foo suite 1', () => {
  let i = 0;
  while (i++ < 50) {
    it(`test #${i}`, async () => {
      await new Promise((resolve) => setTimeout(resolve, 100));
    });
  }
});

// overrides any value of --test-concurrency with 2
describe('foo suite 2', {
  concurrency: 3,
}, () => {
  let i = 0;
  while (i++ < 100) {
    it(`test #${i}`, async () => {
      await new Promise((resolve) => setTimeout(resolve, 100));
    });
  }
});

// overrides any value of --test-concurrency with require('os').availableParallelism()
describe('foo suite 3', {
  concurrency: true,
}, () => {
  let i = 0;
  while (i++ < 10000) {
    it(`test #${i}`, async () => {
      await new Promise((resolve) => setTimeout(resolve, 100));
    });
  }
});
  1. run:
# should default to require('os').availableParallelism(), but seems to default to concurrency of 1 or whatever value the test suite defines (aka { concurrecy: <value> })
node --test foo.test.mjs

# should run with concurrency of 7, but seems to still use 1 or whatever the test suite defines
node --test --test-concurrency=7 foo.test.mjs

# should run with concurrency of 1, but seems to still use 1 or whatever the test suite defines
node --test --test-concurrency=1 foo.test.mjs

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

--test-concurrency should have an effect and behave as defined in the docs.

What do you see instead?

--test-concurrency has zero effect. You can see evidence of this by looking at the time each suite takes to complete:

# 50 tests
▶ foo suite 1 (5086.684417ms)
# 100 tests
▶ foo suite 2 (3457.998ms)
# 10000 tests
▶ foo suite 3 (658.40475ms)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions