Skip to content
Closed
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: 6 additions & 0 deletions lib/internal/test_runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,12 @@ function run(options = kEmptyObject) {
finishBootstrap();
return root.processPendingSubtests();
};

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
44 changes: 44 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,44 @@
'use strict';

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

if (cluster.isPrimary) {
cluster.fork().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
const stream = run({
isolation: 'none',
files: [
join(__dirname, 'default-behavior', 'test', 'random.cjs'),
],
});

async function consumeStream() {
for await (const data of stream) {
if (data === undefined) {
continue;
}
}
process.stdout.write('on end\n');
process.exit(0);
}

consumeStream().catch((err) => {
process.stderr.write(`worker error: ${err}\n`);
process.exit(1);
});

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(5000),
});

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

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