Skip to content

Commit

Permalink
test: reduce flakiness of test-esm-loader-hooks
Browse files Browse the repository at this point in the history
PR-URL: #49248
Backport-PR-URL: #50669
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Nov 23, 2023
1 parent 58eaf3f commit e1c6f46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions test/es-module/test-esm-loader-hooks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,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);
Expand All @@ -558,8 +558,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();
`,
]);
Expand Down Expand Up @@ -655,10 +659,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);
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/es-module-loaders/hooks-initialize.mjs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit e1c6f46

Please sign in to comment.