Skip to content

Commit

Permalink
test: do not set concurrency on parallelized runs
Browse files Browse the repository at this point in the history
Our CI already run test files in parallel, having `node:test` spawns
child processes concurrently could lead to oversubscribing the CI
machine. This commit sets the `concurrency` depending
on the presence of `TEST_PARALLEL` in the env, so running the test
file individually still spawns child processes concurrently, and
running the whole test suite does not oversubscribe the machine.

PR-URL: nodejs#52177
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
aduh95 authored and rdw-msft committed Mar 26, 2024
1 parent 35a21d9 commit dda083b
Show file tree
Hide file tree
Showing 47 changed files with 79 additions and 67 deletions.
2 changes: 1 addition & 1 deletion test/es-module/test-cjs-esm-warn.js
Expand Up @@ -15,7 +15,7 @@ const pjson = path.resolve(
);


describe('CJS ↔︎ ESM interop warnings', { concurrency: true }, () => {
describe('CJS ↔︎ ESM interop warnings', { concurrency: !process.env.TEST_PARALLEL }, () => {

it(async () => {
const required = path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-cjs-exports.js
Expand Up @@ -7,7 +7,7 @@ const { execPath } = require('node:process');
const { describe, it } = require('node:test');


describe('ESM: importing CJS', { concurrency: true }, () => {
describe('ESM: importing CJS', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should support valid CJS exports', async () => {
const validEntry = fixtures.path('/es-modules/cjs-exports.mjs');
const { code, signal, stdout } = await spawnPromisified(execPath, [validEntry]);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-cjs-load-error-note.mjs
Expand Up @@ -19,7 +19,7 @@ const mustNotIncludeMessage = {
includeNote: false,
};

describe('ESM: Errors for unexpected exports', { concurrency: true }, () => {
describe('ESM: Errors for unexpected exports', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (
const { errorNeedle, filePath, getMessage, includeNote }
of [
Expand Down
14 changes: 7 additions & 7 deletions test/es-module/test-esm-detect-ambiguous.mjs
Expand Up @@ -4,8 +4,8 @@ import { spawn } from 'node:child_process';
import { describe, it } from 'node:test';
import { strictEqual, match } from 'node:assert';

describe('--experimental-detect-module', { concurrency: true }, () => {
describe('string input', { concurrency: true }, () => {
describe('--experimental-detect-module', { concurrency: !process.env.TEST_PARALLEL }, () => {
describe('string input', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('permits ESM syntax in --eval input without requiring --input-type=module', async () => {
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
'--experimental-detect-module',
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
});
});

describe('.js file input in a typeless package', { concurrency: true }, () => {
describe('.js file input in a typeless package', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (const { testName, entryPath } of [
{
testName: 'permits CommonJS syntax in a .js entry point',
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
}
});

describe('extensionless file input in a typeless package', { concurrency: true }, () => {
describe('extensionless file input in a typeless package', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (const { testName, entryPath } of [
{
testName: 'permits CommonJS syntax in an extensionless entry point',
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
});
});

describe('file input in a "type": "commonjs" package', { concurrency: true }, () => {
describe('file input in a "type": "commonjs" package', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (const { testName, entryPath } of [
{
testName: 'disallows ESM syntax in a .js entry point',
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
}
});

describe('file input in a "type": "module" package', { concurrency: true }, () => {
describe('file input in a "type": "module" package', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (const { testName, entryPath } of [
{
testName: 'disallows CommonJS syntax in a .js entry point',
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('--experimental-detect-module', { concurrency: true }, () => {
});

// https://github.com/nodejs/node/issues/50917
describe('syntax that errors in CommonJS but works in ESM', { concurrency: true }, () => {
describe('syntax that errors in CommonJS but works in ESM', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('permits top-level `await`', async () => {
const { stdout, stderr, code, signal } = await spawnPromisified(process.execPath, [
'--experimental-detect-module',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-experimental-warnings.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: warn for obsolete hooks provided', { concurrency: true }, () => {
describe('ESM: warn for obsolete hooks provided', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should not print warnings when no experimental features are enabled or used', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--input-type=module',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-export-not-found.mjs
Expand Up @@ -12,7 +12,7 @@ const importStatementMultiline = `import {
} from './module-named-exports.mjs';
`;

describe('ESM: nonexistent exports', { concurrency: true }, () => {
describe('ESM: nonexistent exports', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (
const { name, input }
of [
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-extension-lookup-deprecation.mjs
Expand Up @@ -7,7 +7,7 @@ import * as path from 'node:path';
import { execPath } from 'node:process';
import { describe, it, before } from 'node:test';

describe('ESM in main field', { concurrency: true }, () => {
describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () => {
before(() => tmpdir.refresh());

it('should handle fully-specified relative path without any warning', async () => {
Expand Down
12 changes: 8 additions & 4 deletions test/es-module/test-esm-extensionless-esm-and-wasm.mjs
Expand Up @@ -4,7 +4,9 @@ import * as fixtures from '../common/fixtures.mjs';
import { describe, it } from 'node:test';
import { match, ok, strictEqual } from 'node:assert';

describe('extensionless ES modules within a "type": "module" package scope', { concurrency: true }, () => {
describe('extensionless ES modules within a "type": "module" package scope', {
concurrency: !process.env.TEST_PARALLEL,
}, () => {
it('should run as the entry point', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
fixtures.path('es-modules/package-type-module/noext-esm'),
Expand All @@ -29,7 +31,9 @@ describe('extensionless ES modules within a "type": "module" package scope', { c
strictEqual(defaultExport, 'module');
});
});
describe('extensionless Wasm modules within a "type": "module" package scope', { concurrency: true }, () => {
describe('extensionless Wasm modules within a "type": "module" package scope', {
concurrency: !process.env.TEST_PARALLEL,
}, () => {
it('should run as the entry point', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-wasm-modules',
Expand All @@ -55,7 +59,7 @@ describe('extensionless Wasm modules within a "type": "module" package scope', {
});
});

describe('extensionless ES modules within no package scope', { concurrency: true }, () => {
describe('extensionless ES modules within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
// This succeeds with `--experimental-default-type=module`
it('should error as the entry point', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
Expand All @@ -79,7 +83,7 @@ describe('extensionless ES modules within no package scope', { concurrency: true
});
});

describe('extensionless Wasm within no package scope', { concurrency: true }, () => {
describe('extensionless Wasm within no package scope', { concurrency: !process.env.TEST_PARALLEL }, () => {
// This succeeds with `--experimental-default-type=module`
it('should error as the entry point', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-import-flag.mjs
Expand Up @@ -10,7 +10,7 @@ const mjsEntry = fixtures.path('es-modules', 'mjs-file.mjs');
const mjsImport = fixtures.fileURL('es-modules', 'mjs-file.mjs');


describe('import modules using --import', { concurrency: true }, () => {
describe('import modules using --import', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should import when using --eval', async () => {
const { code, signal, stderr, stdout } = await spawnPromisified(
execPath,
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-import-json-named-export.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: named JSON exports', { concurrency: true }, () => {
describe('ESM: named JSON exports', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should throw, citing named import', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
fixtures.path('es-modules', 'import-json-named-export.mjs'),
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-initialization.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: ensure initialization happens only once', { concurrency: true }, () => {
describe('ESM: ensure initialization happens only once', { concurrency: !process.env.TEST_PARALLEL }, () => {
it(async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
'--experimental-import-meta-resolve',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-invalid-pjson.js
Expand Up @@ -7,7 +7,7 @@ const { execPath } = require('node:process');
const { describe, it } = require('node:test');


describe('ESM: Package.json', { concurrency: true }, () => {
describe('ESM: Package.json', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should throw on invalid pson', async () => {
const entry = fixtures.path('/es-modules/import-invalid-pjson.mjs');
const invalidJson = fixtures.path('/node_modules/invalid-pjson/package.json');
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-chaining.mjs
Expand Up @@ -15,7 +15,7 @@ const commonArgs = [
commonInput,
];

describe('ESM: loader chaining', { concurrency: true }, () => {
describe('ESM: loader chaining', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should load unadulterated source when there are no loaders', async () => {
const { code, stderr, stdout } = await spawnPromisified(
execPath,
Expand Down
6 changes: 3 additions & 3 deletions test/es-module/test-esm-loader-hooks.mjs
Expand Up @@ -4,7 +4,7 @@ import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';

describe('Loader hooks', { concurrency: true }, () => {
describe('Loader hooks', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('are called with all expected arguments', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Loader hooks', { concurrency: true }, () => {
assert.strictEqual(lines.length, 5);
});

describe('should handle never-settling hooks in ESM files', { concurrency: true }, () => {
describe('should handle never-settling hooks in ESM files', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('top-level await of a never-settling resolve without warning', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('Loader hooks', { concurrency: true }, () => {
});
});

describe('should handle never-settling hooks in CJS files', { concurrency: true }, () => {
describe('should handle never-settling hooks in CJS files', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('never-settling resolve', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-http-imports.mjs
Expand Up @@ -46,7 +46,7 @@ const {
port,
} = server.address();

describe('ESM: http import via loader', { concurrency: true }, () => {
describe('ESM: http import via loader', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should load using --import flag', async () => {
// ! MUST NOT use spawnSync to avoid blocking the event loop
const { code, signal, stderr, stdout } = await spawnPromisified(
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-loader-programmatically.mjs
Expand Up @@ -20,7 +20,7 @@ const commonEvals = {
staticImport: (module) => `import ${JSON.stringify(`data:text/javascript,${encodeURIComponent(module)}`)};`,
};

describe('ESM: programmatically register loaders', { concurrency: true }, () => {
describe('ESM: programmatically register loaders', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('works with only a dummy CLI argument', async () => {
const parentURL = fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs');
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('ESM: programmatically register loaders', { concurrency: true }, () =>
assert.strictEqual(lines[5], '');
});

describe('registering via --import', { concurrency: true }, () => {
describe('registering via --import', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (const moduleType of ['mjs', 'cjs']) {
it(`should programmatically register a loader from a ${moduleType.toUpperCase()} file`, async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
Expand Down
4 changes: 2 additions & 2 deletions test/es-module/test-esm-loader-spawn-promisified.mjs
Expand Up @@ -4,7 +4,7 @@ import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';

describe('Loader hooks throwing errors', { concurrency: true }, () => {
describe('Loader hooks throwing errors', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('throws on nonexistent modules', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
});
});

describe('Loader hooks parsing modules', { concurrency: true }, () => {
describe('Loader hooks parsing modules', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('can parse .js files as ESM', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-thenable.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: thenable loader hooks', { concurrency: true }, () => {
describe('ESM: thenable loader hooks', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should behave as a normal promise resolution', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-with-syntax-error.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: loader with syntax error', { concurrency: true }, () => {
describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should crash the node process', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
'--experimental-loader',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-module-not-found-commonjs-hint.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: module not found hint', { concurrency: true }, () => {
describe('ESM: module not found hint', { concurrency: !process.env.TEST_PARALLEL }, () => {
for (
const { input, expected, cwd = fixturesDir }
of [
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-non-js.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: non-js extensions fail', { concurrency: true }, () => {
describe('ESM: non-js extensions fail', { concurrency: !process.env.TEST_PARALLEL }, () => {
it(async () => {
const { code, stderr, signal } = await spawnPromisified(execPath, [
'--input-type=module',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-nowarn-exports.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: experiemental warning for import.meta.resolve', { concurrency: true }, () => {
describe('ESM: experiemental warning for import.meta.resolve', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should not warn when caught', async () => {
const { code, signal, stderr } = await spawnPromisified(execPath, [
'--experimental-import-meta-resolve',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-preserve-symlinks-main.js
Expand Up @@ -41,7 +41,7 @@ try {
skip('insufficient privileges for symlinks');
}

describe('Invoke the main file via a symlink.', { concurrency: true }, () => {
describe('Invoke the main file via a symlink.', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should resolve relative imports in the main file', async () => {
const { code } = await spawnPromisified(execPath, [
'--preserve-symlinks',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-repl-imports.js
Expand Up @@ -8,7 +8,7 @@ const { execPath } = require('node:process');
const { describe, it } = require('node:test');


describe('ESM: REPL runs', { concurrency: true }, () => {
describe('ESM: REPL runs', { concurrency: !process.env.TEST_PARALLEL }, () => {
it((t, done) => {
const child = spawn(execPath, [
'--interactive',
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-source-map.mjs
Expand Up @@ -4,7 +4,7 @@ import assert from 'node:assert';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';

describe('esm source-map', { concurrency: true }, () => {
describe('esm source-map', { concurrency: !process.env.TEST_PARALLEL }, () => {
// Issue: https://github.com/nodejs/node/issues/51522

[
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-syntax-error.mjs
Expand Up @@ -5,7 +5,7 @@ import { execPath } from 'node:process';
import { describe, it } from 'node:test';


describe('ESM: importing a module with syntax error(s)', { concurrency: true }, () => {
describe('ESM: importing a module with syntax error(s)', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should throw', async () => {
const { code, stderr } = await spawnPromisified(execPath, [
path('es-module-loaders', 'syntax-error.mjs'),
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-tla-unfinished.mjs
Expand Up @@ -10,7 +10,7 @@ const commonArgs = [
'--eval',
];

describe('ESM: unsettled and rejected promises', { concurrency: true }, () => {
describe('ESM: unsettled and rejected promises', { concurrency: !process.env.TEST_PARALLEL }, () => {
it('should exit for an unsettled TLA promise via --eval with a warning', async () => {
const { code, stderr, stdout } = await spawnPromisified(execPath, [
...commonArgs,
Expand Down
8 changes: 6 additions & 2 deletions test/es-module/test-esm-type-flag-cli-entry.mjs
Expand Up @@ -3,7 +3,9 @@ import * as fixtures from '../common/fixtures.mjs';
import { describe, it } from 'node:test';
import { match, strictEqual } from 'node:assert';

describe('--experimental-default-type=module should not support extension searching', { concurrency: true }, () => {
describe('--experimental-default-type=module should not support extension searching', {
concurrency: !process.env.TEST_PARALLEL,
}, () => {
it('should support extension searching under --experimental-default-type=commonjs', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=commonjs',
Expand Down Expand Up @@ -33,7 +35,9 @@ describe('--experimental-default-type=module should not support extension search
});
});

describe('--experimental-default-type=module should not parse paths as URLs', { concurrency: true }, () => {
describe('--experimental-default-type=module should not parse paths as URLs', {
concurrency: !process.env.TEST_PARALLEL,
}, () => {
it('should not parse a `?` in a filename as starting a query string', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
Expand Down
6 changes: 4 additions & 2 deletions test/es-module/test-esm-type-flag-errors.mjs
Expand Up @@ -3,8 +3,10 @@ import * as fixtures from '../common/fixtures.mjs';
import { describe, it } from 'node:test';
import { deepStrictEqual, match, strictEqual } from 'node:assert';

describe('--experimental-default-type=module', { concurrency: true }, () => {
describe('should not affect the interpretation of files with unknown extensions', { concurrency: true }, () => {
describe('--experimental-default-type=module', { concurrency: !process.env.TEST_PARALLEL }, () => {
describe('should not affect the interpretation of files with unknown extensions', {
concurrency: !process.env.TEST_PARALLEL,
}, () => {
it('should error on an entry point with an unknown extension', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
Expand Down

0 comments on commit dda083b

Please sign in to comment.