From f7a0dbb2516c7567da4b885d18b26ed6407dadb1 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 15 Oct 2025 22:26:15 +0200 Subject: [PATCH] test: parallelize test-without-async-context-frame correctly It previously re-einvented the pattern matching that's already supported by test.py, and was running the tests one by one, which can lead to time out on slower machines. This move it to sequential and use wildcard support in test.py to correctly parallelize the tests. --- .../test-without-async-context-frame.mjs | 64 ------------------- .../test-without-async-context-frame.mjs | 24 +++++++ 2 files changed, 24 insertions(+), 64 deletions(-) delete mode 100644 test/parallel/test-without-async-context-frame.mjs create mode 100644 test/sequential/test-without-async-context-frame.mjs diff --git a/test/parallel/test-without-async-context-frame.mjs b/test/parallel/test-without-async-context-frame.mjs deleted file mode 100644 index fa431c5700053c..00000000000000 --- a/test/parallel/test-without-async-context-frame.mjs +++ /dev/null @@ -1,64 +0,0 @@ -import { isWindows } from '../common/index.mjs'; -import { spawn } from 'node:child_process'; -import { once } from 'node:events'; -import { opendir } from 'node:fs/promises'; -import { fileURLToPath } from 'node:url'; -import { describe, it } from 'node:test'; -import { sep } from 'node:path'; -import { strictEqual } from 'node:assert'; - -const python = process.env.PYTHON || (isWindows ? 'python' : 'python3'); - -const testRunner = fileURLToPath( - new URL('../../tools/test.py', import.meta.url) -); - -const setNames = ['async-hooks', 'parallel']; - -// Get all test names for each set -const testSets = await Promise.all(setNames.map(async (name) => { - const path = fileURLToPath(new URL(`../${name}`, import.meta.url)); - const dir = await opendir(path); - - const tests = []; - for await (const entry of dir) { - if (entry.name.startsWith('test-async-local-storage-')) { - tests.push(entry.name); - } - } - - return { - name, - tests - }; -})); - -// Merge test sets with set name prefix -const tests = testSets.reduce((m, v) => { - for (const test of v.tests) { - m.push(`${v.name}${sep}${test}`); - } - return m; -}, []); - -describe('without AsyncContextFrame', { - // TODO(qard): I think high concurrency causes memory problems on Windows - // concurrency: tests.length -}, () => { - for (const test of tests) { - it(test, async () => { - const proc = spawn(python, [ - testRunner, - `--mode=${process.features.debug ? 'debug' : 'release'}`, - `--shell=${process.execPath}`, - '--node-args=--no-async-context-frame', - test, - ], { - stdio: ['ignore', 'ignore', 'inherit'], - }); - - const [code] = await once(proc, 'exit'); - strictEqual(code, 0, `Test ${test} failed with exit code ${code}`); - }); - } -}); diff --git a/test/sequential/test-without-async-context-frame.mjs b/test/sequential/test-without-async-context-frame.mjs new file mode 100644 index 00000000000000..087bb67b71af78 --- /dev/null +++ b/test/sequential/test-without-async-context-frame.mjs @@ -0,0 +1,24 @@ +import { isWindows } from '../common/index.mjs'; +import { spawn } from 'node:child_process'; +import { once } from 'node:events'; +import { fileURLToPath } from 'node:url'; +import { strictEqual } from 'node:assert'; + +const python = process.env.PYTHON || (isWindows ? 'python' : 'python3'); + +const testRunner = fileURLToPath( + new URL('../../tools/test.py', import.meta.url) +); + +const proc = spawn(python, [ + testRunner, + `--mode=${process.features.debug ? 'debug' : 'release'}`, + `--shell=${process.execPath}`, + '--node-args=--no-async-context-frame', + '*/test-async-local-storage-*', +], { + stdio: ['inherit', 'inherit', 'inherit'], +}); + +const [code] = await once(proc, 'exit'); +strictEqual(code, 0);