Skip to content
Merged
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
5 changes: 5 additions & 0 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export default function loadFork(file, options, execArgv = process.execArgv) {
}

switch (message.ava.type) {
case 'worker-finished': {
send({type: 'free-worker'});
break;
}

case 'ready-for-options': {
send({type: 'options', options});
break;
Expand Down
9 changes: 9 additions & 0 deletions lib/worker/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ const run = async options => {
return;
}

channel.send({type: 'worker-finished'});

// Reference the channel until the worker is freed. This should prevent Node.js from terminating the child process
// prematurely, which has been witnessed on Windows. See discussion at
// <https://github.com/avajs/ava/issues/3390#issuecomment-3056119361>.
channel.ref();
await channel.workerFreed;
channel.unref();

nowAndTimers.setImmediate(() => {
const unhandled = currentlyUnhandled();
if (unhandled.length === 0) {
Expand Down
2 changes: 2 additions & 0 deletions lib/worker/channel.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ handle.ref();

exports.options = selectAvaMessage(handle.channel, 'options').then(message => message.ava.options);
exports.peerFailed = selectAvaMessage(handle.channel, 'peer-failed');
exports.workerFreed = selectAvaMessage(handle.channel, 'free-worker');
exports.send = handle.send.bind(handle);
exports.ref = handle.ref.bind(handle);
exports.unref = handle.unref.bind(handle);

let channelCounter = 0;
Expand Down
3 changes: 3 additions & 0 deletions test/child-process/fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
7 changes: 7 additions & 0 deletions test/child-process/fixtures/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava';

for (let i = 0; i < 50; i++) {
test('Test ' + (i + 1), t => {
t.true(true);
});
}
9 changes: 9 additions & 0 deletions test/child-process/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import test from '@ava/test';

import {fixture} from '../helpers/exec.js';

// Regression test for https://github.com/avajs/ava/issues/3390
test('running 50 tests in a child process works as expected', async t => {
const result = await fixture(['--no-worker-threads']);
t.is(result.stats.passed.length, 50);
});
Loading