Skip to content
Draft
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
13 changes: 12 additions & 1 deletion lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,19 @@ function run(options = kEmptyObject) {
debug('beginning test execution');
root.entryFile = null;
finishBootstrap();
return root.processPendingSubtests();
const pendingSubtestsPromise = root.processPendingSubtests();
if (!isTestRunner) {
PromisePrototypeThen(pendingSubtestsPromise, undefined, triggerUncaughtException);
return;
}
return pendingSubtestsPromise;
};

if (!isTestRunner) {
// run() API consumers can keep handles alive (e.g., IPC). Finalize
// without waiting for beforeExit so the stream can close promptly.
teardown = () => root.harness.teardown();
}
}
}

Expand Down
45 changes: 45 additions & 0 deletions test/fixtures/test-runner/run-isolation-none-in-cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const cluster = require('node:cluster');
const { join } = require('node:path');
const { run } = require('node:test');

if (cluster.isPrimary) {
const worker = cluster.fork();
worker.on('exit', (code, signal) => {
if (signal !== null) {
process.stderr.write(`worker exited with signal ${signal}\n`);
process.exit(1);
}

process.exit(code ?? 0);
});
} else {
// Repro based on: https://github.com/nodejs/node/issues/60020
// We pin `files` for deterministic test discovery in CI.
const stream = run({
isolation: 'none',
files: [
join(__dirname, 'default-behavior', 'test', 'random.cjs'),
],
});

stream.on('error', (err) => {
process.stderr.write(`worker error: ${err}\n`);
process.exit(1);
});

stream.on('data', (data) => {
process.stdout.write(`on data ${data.type}\n`);
});

stream.on('end', () => {
process.stdout.write('on end\n');
process.exit(0);
});

setTimeout(() => {
process.stderr.write('worker timed out waiting for end\n');
process.exit(1);
}, 3000).unref();
}
14 changes: 14 additions & 0 deletions test/parallel/test-runner-run.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as common from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
import { describe, it, run } from 'node:test';
import { dot, spec, tap } from 'node:test/reporters';
import consumers from 'node:stream/consumers';
Expand Down Expand Up @@ -646,6 +647,19 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
assert.strictEqual(diagnostics.includes(entry), true);
}
});

// Regression test for https://github.com/nodejs/node/issues/60020
it('should not hang in cluster workers when isolation is none', () => {
const fixture = fixtures.path('test-runner', 'run-isolation-none-in-cluster.js');
const { status, signal, stdout, stderr } = spawnSync(process.execPath, [fixture], {
encoding: 'utf8',
timeout: common.platformTimeout(15_000),
});

assert.strictEqual(signal, null);
assert.strictEqual(status, 0, stderr);
assert.match(stdout, /on end/);
});
});

describe('env', () => {
Expand Down