Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/fixtures/process-timeout/blocked-worker-at-exit.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -26,5 +26,3 @@ const interval = setInterval(() => {
worker.unref();
}
}, 10);

process.on('exit', () => fs.writeFileSync(marker, ''));
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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, ''));
10 changes: 7 additions & 3 deletions test/parallel/test-process-timeout-blocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
Loading