mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
test: reduce flakiness of test-esm-loader-hooks
PR-URL: https://github.com/nodejs/node/pull/49248 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
1 parent
34a2590b05
commit
910378f93f
2 files changed
+13
-8
No files matched your search
@@ -599,7 +599,7 @@ describe('Loader hooks', { concurrency: true }, () => {
|
||||
`
|
||||
import {MessageChannel} from 'node:worker_threads';
|
||||
import {register} from 'node:module';
|
||||
import {setTimeout} from 'node:timers/promises';
|
||||
import {once} from 'node:events';
|
||||
const {port1, port2} = new MessageChannel();
|
||||
port1.on('message', (msg) => {
|
||||
console.log('message', msg);
|
||||
@@ -610,8 +610,12 @@ describe('Loader hooks', { concurrency: true }, () => {
|
||||
);
|
||||
console.log('register', result);
|
||||
|
||||
await import('node:os');
|
||||
await setTimeout(99); // delay to limit flakiness
|
||||
const timeout = setTimeout(() => {}, 2**31 - 1); // to keep the process alive.
|
||||
await Promise.all([
|
||||
once(port1, 'message').then(() => once(port1, 'message')),
|
||||
import('node:os'),
|
||||
]);
|
||||
clearTimeout(timeout);
|
||||
port1.close();
|
||||
`,
|
||||
]);
|
||||
@@ -707,10 +711,10 @@ describe('Loader hooks', { concurrency: true }, () => {
|
||||
]);
|
||||
|
||||
assert.strictEqual(stderr, '');
|
||||
assert.deepStrictEqual(stdout.split('\n'), [ 'result 1',
|
||||
'result 2',
|
||||
'hooks initialize 1',
|
||||
assert.deepStrictEqual(stdout.split('\n'), [ 'hooks initialize 1',
|
||||
'result 1',
|
||||
'hooks initialize 2',
|
||||
'result 2',
|
||||
'' ]);
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
import { writeFileSync } from 'node:fs';
|
||||
|
||||
let counter = 0;
|
||||
|
||||
export async function initialize() {
|
||||
counter += 1;
|
||||
console.log('hooks initialize', counter);
|
||||
writeFileSync(1, `hooks initialize ${++counter}\n`);
|
||||
return counter;
|
||||
}
|
||||
Reference in new issue
Block a user