mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: rewrite AsyncLocalStorage without async_hooks
PR-URL: https://github.com/nodejs/node/pull/48528 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
parent
0c1877a82a
commit
d1229eeca4
29 changed files with 658 additions and 173 deletions
59
test/parallel/test-async-context-frame.mjs
Normal file
59
test/parallel/test-async-context-frame.mjs
Normal file
|
@ -0,0 +1,59 @@
|
|||
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';
|
||||
|
||||
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('AsyncContextFrame', {
|
||||
concurrency: tests.length
|
||||
}, () => {
|
||||
for (const test of tests) {
|
||||
it(test, async () => {
|
||||
const proc = spawn(python, [
|
||||
testRunner,
|
||||
'--node-args=--experimental-async-context-frame',
|
||||
test,
|
||||
], {
|
||||
stdio: ['ignore', 'ignore', 'inherit'],
|
||||
});
|
||||
|
||||
await once(proc, 'exit');
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue