diff --git a/test/fixtures/process-timeout/blocked-worker-at-exit.js b/test/fixtures/process-timeout/blocked-worker-at-exit.js index 5ff21b423f62..febad9d0c58f 100644 --- a/test/fixtures/process-timeout/blocked-worker-at-exit.js +++ b/test/fixtures/process-timeout/blocked-worker-at-exit.js @@ -1,8 +1,8 @@ 'use strict'; // Lets the event loop stop while a Worker is blocked in a synchronous native -// call, so that exiting the process waits for the Worker. The first argument is -// a path at which a file is created once the event loop has stopped. +// call, so that exiting the process waits for the Worker. The child process +// creates a file named after the first argument once it has started. const fs = require('fs'); const path = require('path'); const { Worker } = require('worker_threads'); @@ -26,5 +26,3 @@ const interval = setInterval(() => { worker.unref(); } }, 10); - -process.on('exit', () => fs.writeFileSync(marker, '')); diff --git a/test/fixtures/process-timeout/blocked-worker-at-process-exit.js b/test/fixtures/process-timeout/blocked-worker-at-process-exit.js index b7e853e62f6b..05afe71fa2e6 100644 --- a/test/fixtures/process-timeout/blocked-worker-at-process-exit.js +++ b/test/fixtures/process-timeout/blocked-worker-at-process-exit.js @@ -1,7 +1,7 @@ 'use strict'; // Exits the process while a Worker is blocked in a synchronous native call, so -// that exiting the process waits for the Worker. The first argument is a path -// at which a file is created once the process is exiting. The second argument +// that exiting the process waits for the Worker. The child process creates a +// file named after the first argument once it has started. The second argument // is how the process exits: 'exit' calls process.exit(), 'throw' throws an // uncaught exception, and 'reject' leaves a promise rejection unhandled. const fs = require('fs'); @@ -27,5 +27,3 @@ const interval = setInterval(() => { if (mode === 'reject') return Promise.reject(new Error('boom')); process.exit(0); }, 10); - -process.on('exit', () => fs.writeFileSync(marker, '')); diff --git a/test/parallel/test-process-timeout-blocked.js b/test/parallel/test-process-timeout-blocked.js index db3553e11d59..84c3ecb937e7 100644 --- a/test/parallel/test-process-timeout-blocked.js +++ b/test/parallel/test-process-timeout-blocked.js @@ -13,8 +13,10 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); // The deadline is measured from the start of the process, so on a slow machine -// it can expire before the fixture has reached the state under test, which the -// fixture signals by creating a file. If it did not get that far and did not +// it can expire before the fixture has reached the state under test. Unless the +// main thread is blocked or exiting by then, it handles the timeout and prints +// what it was doing. A fixture that expects it to do so signals that it got far +// enough by creating a file. If the fixture did not get that far and did not // print the expected message, run it again with a longer timeout. function runUntilReady(fixture, expected, args = []) { for (let timeout = common.platformTimeout(1000); ; timeout *= 2) { @@ -30,7 +32,9 @@ function runUntilReady(fixture, expected, args = []) { ], { encoding: 'utf8' }); const elapsed = Number(process.hrtime.bigint() - start) / 1e6; - if (!expected.test(child.stderr) && !fs.existsSync(marker) && + if (!expected.test(child.stderr) && + /^Main thread was/m.test(child.stderr) && + !fs.existsSync(marker) && timeout < common.platformTimeout(16000)) { continue; }