Skip to content

Shared worker teardown #2734

Open
Open
@novemberborn

Description

@novemberborn

Based on this discussion it'd be great to have a teardown method within the shared worker. E.g. after negotiating the protocol, you can call .teardown() to register a callback.

Under normal use, after a test run, AVA can explicitly message the shared workers to begin their teardown. They must then respond when complete. The worker may then exit on its own or be terminated explicitly.

In watch mode, AVA should keep the workers alive until it's made to exit. It should then tear down the workers gracefully, as per above.

We should no longer unreference the worker:

launched.worker.unref();

Looking at this now, the whole deregistration bit here makes no sense:

let registrationCount = 0;
let signalDeregistered;
const deregistered = new Promise(resolve => {
signalDeregistered = resolve;
});

The shared worker may end up in a "deregistered" state if ever there is a gap between test workers using it.

The API instance should probably track shared worker instances, not in a per-run variable like now, but on the instance itself. This will require some rewiring:

ava/lib/api.js

Line 236 in bdf2cf0

deregisteredSharedWorkers.push(sharedWorkers.observeWorkerProcess(worker, runStatus));

Then, perhaps, we could add a teardown() method to the API itself, which we can call after its run completes:

ava/lib/cli.js

Line 467 in bdf2cf0

const runStatus = await api.run({filter});

Watch mode requires the process to be "killed" using a SIGINT signal. This is currently handled internally be the API instance:

ava/lib/api.js

Line 55 in d742672

process.on('SIGINT', () => this._interruptHandler());

And then per run:

ava/lib/api.js

Line 96 in d742672

this._interruptHandler = () => {

It might make more sense to register for SIGINT in the lib/cli.js file and then call an interrupt() method on the API instance, after which we can kick off the teardown.

When SIGINT is received a second time we should forcibly exit the process, without waiting for a graceful teardown of the shared workers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions