From 9de718f6708f3806a962b6a8155e7cc12f9f5117 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Wed, 7 Dec 2022 15:31:22 -0800 Subject: [PATCH 1/3] Add bug reproduction --- test/times-out-with-worker/fixtures/package.json | 9 +++++++++ test/times-out-with-worker/fixtures/test.js | 14 ++++++++++++++ test/times-out-with-worker/fixtures/worker.mjs | 3 +++ test/times-out-with-worker/test.js | 10 ++++++++++ 4 files changed, 36 insertions(+) create mode 100644 test/times-out-with-worker/fixtures/package.json create mode 100644 test/times-out-with-worker/fixtures/test.js create mode 100644 test/times-out-with-worker/fixtures/worker.mjs create mode 100644 test/times-out-with-worker/test.js diff --git a/test/times-out-with-worker/fixtures/package.json b/test/times-out-with-worker/fixtures/package.json new file mode 100644 index 000000000..cbbc24243 --- /dev/null +++ b/test/times-out-with-worker/fixtures/package.json @@ -0,0 +1,9 @@ +{ + "type": "module", + "ava": { + "files": [ + "*.js" + ], + "timeout": "2s" + } +} diff --git a/test/times-out-with-worker/fixtures/test.js b/test/times-out-with-worker/fixtures/test.js new file mode 100644 index 000000000..60f7d9e38 --- /dev/null +++ b/test/times-out-with-worker/fixtures/test.js @@ -0,0 +1,14 @@ +import test from 'ava'; +import {registerSharedWorker} from 'ava/plugin'; +import delay from 'delay'; + +registerSharedWorker({ + filename: new URL('worker.mjs', import.meta.url), + supportedProtocols: ['ava-4'], +}); + +test('time out', async t => { + await delay(10_000); + + t.pass(); +}); diff --git a/test/times-out-with-worker/fixtures/worker.mjs b/test/times-out-with-worker/fixtures/worker.mjs new file mode 100644 index 000000000..fa2d5cabd --- /dev/null +++ b/test/times-out-with-worker/fixtures/worker.mjs @@ -0,0 +1,3 @@ +export default ({negotiateProtocol}) => { + negotiateProtocol(['ava-4']).ready(); +}; diff --git a/test/times-out-with-worker/test.js b/test/times-out-with-worker/test.js new file mode 100644 index 000000000..8c093c80d --- /dev/null +++ b/test/times-out-with-worker/test.js @@ -0,0 +1,10 @@ +import test from '@ava/test'; + +import {fixture} from '../helpers/exec.js'; + +test('times out', async t => { + const error = await t.throwsAsync(async () => fixture()); + + t.is(error.exitCode, 1); + t.true(error.timedOut); +}); From 069f7fb5e6a9719ecedc998336581773fcca5838 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Thu, 8 Dec 2022 13:16:31 -0800 Subject: [PATCH 2/3] =?UTF-8?q?Fix=20bug=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin-support/shared-workers.js | 18 ++++++++---------- .../fixtures/package.json | 2 +- test/times-out-with-worker/test.js | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/plugin-support/shared-workers.js b/lib/plugin-support/shared-workers.js index 94030ced5..1a23fa230 100644 --- a/lib/plugin-support/shared-workers.js +++ b/lib/plugin-support/shared-workers.js @@ -51,8 +51,13 @@ function launchWorker(filename, initialData) { export async function observeWorkerProcess(fork, runStatus) { let registrationCount = 0; let signalDeregistered; + let launched; const deregistered = new Promise(resolve => { - signalDeregistered = resolve; + signalDeregistered = () => { + // Only unref the worker once all test workers have been deregistered, otherwise the worker may exit before test workers are deregistered + launched?.worker.unref(); + resolve(); + }; }); fork.promise.finally(() => { @@ -62,7 +67,7 @@ export async function observeWorkerProcess(fork, runStatus) { }); fork.onConnectSharedWorker(async ({filename, initialData, port, signalError}) => { - const launched = launchWorker(filename, initialData); + launched = launchWorker(filename, initialData); const handleWorkerMessage = async message => { if (message.type === 'deregistered-test-worker' && message.id === fork.threadId) { @@ -104,14 +109,7 @@ export async function observeWorkerProcess(fork, runStatus) { }); launched.worker.on('message', handleWorkerMessage); - } catch { - return; - } finally { - // Attaching listeners has the side-effect of referencing the worker. - // Explicitly unreference it now so it does not prevent the main process - // from exiting. - launched.worker.unref(); - } + } catch {} }); return deregistered; diff --git a/test/times-out-with-worker/fixtures/package.json b/test/times-out-with-worker/fixtures/package.json index cbbc24243..3e7bec51a 100644 --- a/test/times-out-with-worker/fixtures/package.json +++ b/test/times-out-with-worker/fixtures/package.json @@ -4,6 +4,6 @@ "files": [ "*.js" ], - "timeout": "2s" + "timeout": "5s" } } diff --git a/test/times-out-with-worker/test.js b/test/times-out-with-worker/test.js index 8c093c80d..1f82c85ab 100644 --- a/test/times-out-with-worker/test.js +++ b/test/times-out-with-worker/test.js @@ -6,5 +6,4 @@ test('times out', async t => { const error = await t.throwsAsync(async () => fixture()); t.is(error.exitCode, 1); - t.true(error.timedOut); }); From 7daec5b9b57aa33c9baf94a4d956f5975364a76e Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sat, 10 Dec 2022 09:42:07 +0000 Subject: [PATCH 3/3] Move test --- .../timeout}/fixtures/package.json | 0 .../timeout}/fixtures/test.js | 0 .../timeout}/fixtures/worker.mjs | 0 test/{times-out-with-worker => shared-workers/timeout}/test.js | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename test/{times-out-with-worker => shared-workers/timeout}/fixtures/package.json (100%) rename test/{times-out-with-worker => shared-workers/timeout}/fixtures/test.js (100%) rename test/{times-out-with-worker => shared-workers/timeout}/fixtures/worker.mjs (100%) rename test/{times-out-with-worker => shared-workers/timeout}/test.js (76%) diff --git a/test/times-out-with-worker/fixtures/package.json b/test/shared-workers/timeout/fixtures/package.json similarity index 100% rename from test/times-out-with-worker/fixtures/package.json rename to test/shared-workers/timeout/fixtures/package.json diff --git a/test/times-out-with-worker/fixtures/test.js b/test/shared-workers/timeout/fixtures/test.js similarity index 100% rename from test/times-out-with-worker/fixtures/test.js rename to test/shared-workers/timeout/fixtures/test.js diff --git a/test/times-out-with-worker/fixtures/worker.mjs b/test/shared-workers/timeout/fixtures/worker.mjs similarity index 100% rename from test/times-out-with-worker/fixtures/worker.mjs rename to test/shared-workers/timeout/fixtures/worker.mjs diff --git a/test/times-out-with-worker/test.js b/test/shared-workers/timeout/test.js similarity index 76% rename from test/times-out-with-worker/test.js rename to test/shared-workers/timeout/test.js index 1f82c85ab..a90d673ee 100644 --- a/test/times-out-with-worker/test.js +++ b/test/shared-workers/timeout/test.js @@ -1,6 +1,6 @@ import test from '@ava/test'; -import {fixture} from '../helpers/exec.js'; +import {fixture} from '../../helpers/exec.js'; test('times out', async t => { const error = await t.throwsAsync(async () => fixture());