Skip to content

any showcase for node:test concurrency options? #3837

Description

@atian25

Details

as https://nodejs.org/dist/latest-v18.x/docs/api/test.html#testname-options-fn docs says, subtests could run concurrency.

when try as:

test('multi level test', { concurrency: 2 }, async (t) => {
  await t.test('subtest 1', async () => {
    console.log('1');
    await setTimeout(2000);
    console.log('11');
  });

  await t.test('subtest 2', async () => {
    console.log('2');
    await setTimeout(1000);
    console.log('22');
  });
});

itdon't work, since each subtests is awaited.


but if write test like below:

test('multi level test', { concurrency: 2 }, async (t) => {
  t.test('subtest 1', async () => {
    console.log('1');
    await setTimeout(2000);
    console.log('11');
  });

  t.test('subtest 2', async () => {
    console.log('2');
    await setTimeout(1000);
    console.log('22');
  });
});

got error:

not ok 1 - subtest 1
      ---
      duration_ms: 0.001728458
      failureType: 'cancelledByParent'
      error: "'test did not finish before its parent and was cancelled'"
      code: ERR_TEST_FAILURE
      ...

Node.js version

18.0.0

Example code

No response

Operating system

macOS

Scope

test

Module and version

Not applicable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions