Commit 7c3d3e72291 for nodejs
commit 7c3d3e722913c4f6da2450e9cc0a2549d5d349de
Author: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Date: Tue Nov 17 12:13:26 2026 -0300
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>
diff --git a/test/fixtures/process-timeout/blocked-worker-at-exit.js b/test/fixtures/process-timeout/blocked-worker-at-exit.js
index 5ff21b423f6..febad9d0c58 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 b7e853e62f6..05afe71fa2e 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 db3553e11d5..84c3ecb937e 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;
}