Skip to content

Commit cf02160

Browse files
aduh95targos
authored andcommitted
test: reduce flakiness of test-esm-loader-hooks
PR-URL: nodejs#49248 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 222a378 commit cf02160

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

test/es-module/test-esm-loader-hooks.mjs

+10-6
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ describe('Loader hooks', { concurrency: true }, () => {
547547
`
548548
import {MessageChannel} from 'node:worker_threads';
549549
import {register} from 'node:module';
550-
import {setTimeout} from 'node:timers/promises';
550+
import {once} from 'node:events';
551551
const {port1, port2} = new MessageChannel();
552552
port1.on('message', (msg) => {
553553
console.log('message', msg);
@@ -558,8 +558,12 @@ describe('Loader hooks', { concurrency: true }, () => {
558558
);
559559
console.log('register', result);
560560
561-
await import('node:os');
562-
await setTimeout(99); // delay to limit flakiness
561+
const timeout = setTimeout(() => {}, 2**31 - 1); // to keep the process alive.
562+
await Promise.all([
563+
once(port1, 'message').then(() => once(port1, 'message')),
564+
import('node:os'),
565+
]);
566+
clearTimeout(timeout);
563567
port1.close();
564568
`,
565569
]);
@@ -655,10 +659,10 @@ describe('Loader hooks', { concurrency: true }, () => {
655659
]);
656660

657661
assert.strictEqual(stderr, '');
658-
assert.deepStrictEqual(stdout.split('\n'), [ 'result 1',
659-
'result 2',
660-
'hooks initialize 1',
662+
assert.deepStrictEqual(stdout.split('\n'), [ 'hooks initialize 1',
663+
'result 1',
661664
'hooks initialize 2',
665+
'result 2',
662666
'' ]);
663667
assert.strictEqual(code, 0);
664668
assert.strictEqual(signal, null);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { writeFileSync } from 'node:fs';
2+
13
let counter = 0;
24

35
export async function initialize() {
4-
counter += 1;
5-
console.log('hooks initialize', counter);
6+
writeFileSync(1, `hooks initialize ${++counter}\n`);
67
return counter;
78
}

0 commit comments

Comments
 (0)