test: deflake test-process-timeout-blocked

The fixtures that exit while a Worker is blocked created their file in
an 'exit' listener, before the process actually starts exiting, e.g.
while an uncaught error is still being formatted. If the deadline
expired in between, the main thread handled the timeout and the test
failed instead of retrying. The main thread cannot do that once it is
exiting, so retry when it did, and drop the 'exit' listeners.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67481
Refs: https://github.com/nodejs/reliability/issues/1724
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
Christian Aurich Zanettini Martins authored and GitHub committed 2026-11-17 15:13:26 +00:00
1 parent 3db9632585
commit 7c3d3e7229
3 files changed
+11 -11

No files matched your search

+2 -4
View File
@@ -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, ''));
@@ -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, ''));
@@ -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;
}